The question is, if you create a .jar or .exe executable file, will it run on a computer that does not have a JVM and the JDK and JRE are not installed?

  • .jar will not start, but how will you create .exe? - VladD
  • exe is possible, but only under Windows, since with the JVM it is not related to the word at all. jar is not. - rjhdby
  • I don’t know about .exe (it probably depends on how it was created), but it’s impossible to run .jar without JRE, which includes the JVM, normally. - Regent
  • 2
    Purely theoretically, an exe can carry everything you need with you, drop it, set it up, tune it up and then launch the drop jar. The only question is whether it should be so perverted ... - Vladimir Martyanov
  • one
    Possible duplicate question: Creating an exe file for the project Intellij Idea - Artem Konovalov

3 answers 3

Because jar basically cannot work without JVM (because jar is a set of classes in the form of byte-code, and not in the form of executable binary files), then we formulate your question like this: how to package your .jar-project into one .exe file and JVM. So that your project can run and run without pre-installing JVM?

On stackoverflow, they described a successful crossover experiment on launch4j and JVM (i.e. JRE ).

I share a link: how to pack your JAR project and JRE into one EXE file via launch4j .

I translate the answer from the link:

1.Pack your application and JRE into one ZIP archive with directory structure:

 containerFolder |- jre |-bin (здСсь Π»Π΅ΠΆΠΈΡ‚ java.exe ΠΈΠ· состава JRE) |-lib |- cfg (ΠΏΠ°ΠΏΠΊΠ° для сохранСния user-ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ, Ссли Π½ΡƒΠΆΠ½ΠΎ) |- bin (Π’Π°ΡˆΠ΅ ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ с .exe ΠΈ вашим jar-Ρ„Π°ΠΉΠ»ΠΎΠΌ ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΠΌΠΈ Π’Π°ΡˆΠΈΠΌΠΈ внСшними Ρ„Π°ΠΉΠ»Π°ΠΌΠΈ ΠΈΠ· ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°) 

2. In the xml file for launch4j, configure the JRE as follows:

 <jre> <path>../jre</path> <opt>-DgvSIG.confDir=../cfg</opt> </jre> 

The trick is that the path is not specified to the java.exe file. The path to java.exe is indicated relative to the position of the .exe file.

In this example, as a JRE, a regular copy of the standard installed JRE engine is used (for example: C: \ Program Files \ Java \ jre1.8.0_121).

And yes, Launch4j is free and with a very affordable BSD 3-Clause License .

    No, it will not work.

    Did you think well?

    There are packers that pack a version of JRE / JVM into the resulting EXE, in which the jar will be launched.

    For example, ExcelsiorJET is true, it is commercial, but if I search, I think it is free.

    • Hm I wonder what size the resulting exe comes out. - VladD
    • @VladD, since when do you care? The times when RAM size was 4k have already sunk into oblivion :) - Barmaley
    • one
      Well, um, yet packaging an entire virtual machine into an EXE looks somewhat entertaining . :) Plus, deploying this very virtual machine with every launch is also probably not quite free. But yes, it is generally quite a solution. - VladD
    • I love these pearls: enterprise :) - Barmaley
    • Really interesting is the size of the packaged small application. Or rather, such a case is justified for small utilities. - I. Perevoz

    No, it will not work. There is only one alternative. Some packers in exe, can bind it to the local jvm. That is, along with exe will have to drag a folder with jre.