How to create an executable Java file?
Creating a jar File in Command Prompt
Start Command Prompt.Navigate to the folder that holds your class files:
C:>cd \mywork
Set path to include JDK’s bin. For example:
C:\mywork> path c:\Program Files\Java\jdk1.7.0_25\bin;%path%
Compile your class(es):
C:\mywork> javac *.java
Create a manifest file and your jar file:
C:\mywork> echo Main-Class: Craps >manifest.txt
C:\mywork> jar cvfm Craps.jar manifest.txt *.class
or
C:\mywork> jar cvfe Craps.jar Craps *.class
Test your jar:
C:\mywork> Craps.jar
or
C:\mywork> java -jar Craps.jar
Reference link: http://www.skylit.com/javamethods/faqs/createjar.html
How to make an executable JAR file?
A jar file is simply a file containing a collection of java files. To make a jar file executable, you need to specify where the main
Class is in the jar file. Example code would be as follows.
public class JarExample {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
// your logic here
}
});
}
}
Compile your classes. To make a jar, you also need to create a Manifest File (MANIFEST.MF
). For example,
Manifest-Version: 1.0
Main-Class: JarExample
Place the compiled output class files (JarExample.class,JarExample$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command. For example (if you name your manifest file as jexample.mf)
jar cfm jarexample.jar jexample.mf *.class
It will create executable jarexample.jar.
Compiling a java program into an executable
You can convert .jar file to .exe on these ways:
(source: viralpatel.net)
1- JSmooth .exe wrapper:
JSmooth is a Java Executable Wrapper. It creates native Windows launchers (standard .exe) for your java applications. It makes java deployment much smoother and user-friendly, as it is able to find any installed Java VM by itself. When no VM is available, the wrapper can automatically download and install a suitable JVM, or simply display a message or redirect the user to a web site.
JSmooth provides a variety of wrappers for your java application, each of them having their own behaviour: Choose your flavour!
Download: http://jsmooth.sourceforge.net/
2- JarToExe 1.8
Jar2Exe is a tool to convert jar files into exe files.
Following are the main features as describe in their website:
- Can generate “Console”, “Windows GUI”, “Windows Service” three types of exe files.
- Generated exe files can add program icons and version information.
- Generated exe files can encrypt and protect java programs, no temporary files will be generated when program runs.
- Generated exe files provide system tray icon support.
- Generated exe files provide record system event log support.
- Generated windows service exe files are able to install/uninstall itself, and support service pause/continue.
- New release of x64 version, can create 64 bits executives. (May 18, 2008)
- Both wizard mode and command line mode supported. (May 18, 2008)
Download: http://www.brothersoft.com/jartoexe-75019.html
3- Executor
Package your Java application as a jar, and Executor will turn the jar into a Windows exe file, indistinguishable from a native application. Simply double-clicking the exe file will invoke the Java Runtime Environment and launch your application.
Download: http://mpowers.net/executor/
EDIT: The above link is broken, but here is the page (with working download) from the Internet Archive. http://web.archive.org/web/20090316092154/http://mpowers.net/executor/
4- Advanced Installer
Advanced Installer lets you create Windows MSI installs in minutes. This also has Windows Vista support and also helps to create MSI packages in other languages.
Download: http://www.advancedinstaller.com/
Let me know other tools that you have used to convert JAR to EXE.
how can I create executable file for the program written on Java?
- Export .jar in eclipse. (how to)
- Use JSmooth (info) to make an .exe file. (how to)
How can I convert my Java program to an .exe file?
javapackager
The Java Packager tool compiles, packages, and prepares Java and JavaFX applications for distribution. The javapackager command is the command-line version.
– Oracle's documentation
The javapackager
utility ships with the JDK. It can generate .exe files with the -native exe
flag, among many other things.
WinRun4J
WinRun4j is a java launcher for windows. It is an alternative to javaw.exe and provides the following benefits:
- Uses an INI file for specifying classpath, main class, vm args, program args.
- Custom executable name that appears in task manager.
- Additional JVM args for more flexible memory use.
- Built-in icon replacer for custom icon.
- [more bullet points follow]
– WinRun4J's webpage
WinRun4J is an open source utility. It has many features.
packr
Packages your JAR, assets and a JVM for distribution on Windows, Linux and Mac OS X, adding a native executable file to make it appear like a native app. Packr is most suitable for GUI applications.
– packr README
packr is another open source tool.
JSmooth
JSmooth is a Java Executable Wrapper. It creates native Windows launchers (standard .exe) for your java applications. It makes java deployment much smoother and user-friendly, as it is able to find any installed Java VM by itself.
– JSmooth's website
JSmooth is open source and has features, but it is very old. The last release was in 2007.
JexePack
JexePack is a command line tool (great for automated scripting) that allows you to package your Java application (class files), optionally along with its resources (like GIF/JPG/TXT/etc), into a single compressed 32-bit Windows EXE, which runs using Sun's Java Runtime Environment. Both console and windowed applications are supported.
– JexePack's website
JexePack is trialware. Payment is required for production use, and exe files created with this tool will display "reminders" without payment. Also, the last release was in 2013.
InstallAnywhere
InstallAnywhere makes it easy for developers to create professional installation software for any platform. With InstallAnywhere, you’ll adapt to industry changes quickly, get to market faster and deliver an engaging customer experience. And know the vulnerability of your project’s OSS components before you ship.
– InstallAnywhere's website
InstallAnywhere is a commercial/enterprise package that generates installers for Java-based programs. It's probably capable of creating .exe files.
Executable JAR files
As an alternative to .exe files, you can create a JAR file that automatically runs when double-clicked, by adding an entry point to the JAR manifest.
For more information
An excellent source of information on this topic is Excelsior's article "Convert Java to EXE – Why, When, When Not and How".
See also the companion article "Best JAR to EXE Conversion Tools, Free and Commercial".
Related Topics
Can Constructors Throw Exceptions in Java
Why Won't This Generic Java Code Compile
Sorting Arraylist in Alphabetical Order (Case Insensitive)
Why Can't We Use 'This' Keyword in a Static Method
Map Enum in JPA with Fixed Values
What's the Purpose of Try-With-Resources Statements
Changing Mercury Color in Thermometer in Jfreechart
Convert Boolean to Int in Java
Add Context Path to Spring Boot Application
What Causes "Unable to Access Jarfile" Error
How to Represent Double Values as Circles in a 2D Matrix in Java
Whitespace Matching Regex - Java
How to Catch Out of Memory Exception in Java
How Do Synchronized Static Methods Work in Java and How to Use It for Loading Hibernate Entities