9

If you have a small program, you can run jar file and it will work fine. But if you convert jar file into exe, you still need java to run your exe file, so what's the difference between them and why do some people convert jar to exe?

Vegeta
  • 334
  • 2
  • 4
  • 12
  • 3
    Explain _convert jar to exe_. Which exact method for doing this are you asking about? – Boris the Spider Jan 04 '15 at 19:53
  • 3
    Nothing really, the exe presents a method which is common to many users and makes it easier to intergrate into the os (provide icons,,create short cuts etc), but essentially the exe is just a wrapper which launches the jar with the JVM – MadProgrammer Jan 04 '15 at 19:56

5 Answers5

12

An EXE is, ostensibly, an executable program that launches the local java to execute the bundle classes.

As you may know, on your computer you can associate certain file extensions with local programs. For example, .doc files with your word processor.

Similarly, .jar files can be associated with Java, so that Java can execute them. The jar file is considered "stand alone" if it has all of the necessary classes bundled within it, and a proper manifest pointing to the startup class.

So, by associating .jar with Java, clicking on it in your environment will launch Java with the given jar file.

An EXE doesn't need that association. It find java on its own with it's own launcher.

The next step is that you can actually bundle the JRE in to an EXE, so you don't even need to have the user install Java as a pre-requisite. But that's a different process.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
1

People commonly use Java executable wrappers for two reasons - 1. to simply deployment for environments without a JVM, and 2. To make sure the exact Java runtime used for developing the application gets used to run the JAR. However, the practice is not that much widespread.

Monir Zaman
  • 161
  • 3
1

All that the exe will do is to start a jvm with your app, something like this: "java -jar app.jar".

0

Java archive or jar is an archive of compiled java byte code and resources which can be run on a java virtual machine. ".exe" is a windows extension for directly executable code mostly used by installers or programs that do not need to be installed. I think your "people" are talking about installers.

Journeycorner
  • 2,474
  • 3
  • 19
  • 43
0

An Exe file is an executable file that can be executed in Microsoft OS environment. Jar file is container of Java Class files, including other resources related to the project. Jar file can be executed only if Java run time environment. The JavaTM Archive (JAR) file format enables you to bundle multiple files into a single archive file.

The .class files compiled from java files, can not be launched directly. That is why it is needed to be converted to exe before it can run in a windows environment.The usual way to start a java program by batch file is not a convenient way. So inorder to avoid this difficulty we need to convert jar files into exe file.

Also converting it to exe. enables the program to run by simple double click on the program, instead of having to compile it with an IDE or through the JVM.