Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use .jar, versus .exe?

Tags:

java

jar

exe

In Java we can compile soure code into two types of executables: a .jar file, which is basically bytecode, and a .exe file, which is basically machine code. Under what circumstances would it be better to compile to an .exe versus a .jar, and vice-versa? Which one is faster to run? Thanks.

like image 389
George Newton Avatar asked Jan 21 '26 23:01

George Newton


2 Answers

The only reason to create a .exe file is to make it easier to run an application or installer in Windows.

Java compiles to byte code which is then run in the JVM. Normally the .exe is just a wrapper that makes sure that the java VM is started and that the class bytes stored within the .exe (or any other location) are run.

like image 172
Maarten Bodewes Avatar answered Jan 24 '26 13:01

Maarten Bodewes


Not exactly. There are tools that can create .exe files out of Java executable jars, but that's in no way a normal feature of the JDK.

There are very few cases where an .exe file would be an actual necessity, since to run a regular jar you just need to have Java installed and properly configured.

A simple test to decide whether to go for a jar or an exe is to ask yourself "Do you need this to be an .exe file?". If you can't answer that in under 5 seconds, go with a jar file.

like image 40
Kayaman Avatar answered Jan 24 '26 13:01

Kayaman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!