Is there a way to create exe files or binaries in java? I've been only able to create java.class files after compiling the code, but I was wondering whether it is possible to create a normal program in a binary or a exe format that I could run without using command java File
every time I want to run a program.

- 49
- 4
-
just create an executable jar file. If you create an exe, you'll just limit your application to a windows environment. If that's what you want, there might be better languages compared to java – Stultuske Jan 04 '22 at 07:52
-
Several years ago I used Inno Setup 5 to make an exe and standard windows installer from a runnable with a built-in JRE made with JLINK. Info here: https://docs.oracle.com/javase/10/deploy/self-contained-application-packaging.htm#JSDPG600 But it looks like there have been improvements since then to JPACKAGE, and that this can now be used to create a Windows-specific exe. The Java 17 Packaging guide is at https://docs.oracle.com/en/java/javase/17/jpackage/packaging-overview.html – Phil Freihofner Jan 04 '22 at 08:55
-
Heads up, the "previous question" link so helpfully given points to answers that include much obsolete information, with the first solution being 14 years old. – Phil Freihofner Jan 04 '22 at 08:58
3 Answers
The suggested Executable jar files still require a java interpreter to be installed on the system. And as mentioned above, compiling directly into a Windows Executable looses platform independence. Yet it may be desireable to get a more native look and feel during application installation.
For this Oracle/the Java community created JPackage. It wraps your application together with the required JVM such that the whole package can be treated like a native application - regardless whether you want to run on Linux, MacOS or Windows.

- 7,748
- 1
- 16
- 42
You can package all the class files into a .jar
file. This .jar
file is executable by running java -jar <file>.jar
, but most operating systems will allow you, when Java is installed, to double click on the jar file and execute it in this way.
Most build systems (such as maven and gradle) will make it easy for you to create such a file. If you have external dependencies (other jar
files), you will need to create a "fat jar" that also includes those dependencies; there are plugins for those build systems to create fat jars.

- 13,653
- 8
- 51
- 67
You can use Launch4J to make an exe file, here you can find more info - https://youtu.be/jPKxqc8Zg-0

- 55
- 3
- 16