Many newbie have this question how to convert java program to executable file?
To get executable .exe file we must convert .class file to .jar
How to convert .class file to .jar
Create the JAR file. The format of the command line for creating the JAR file looks like this:
"jar cf yourjarfilename manifest.txt Smile.class"
If you want to create executable .exe file of your .class file of java then you have to convert it into
jar (Java ARchive) file this is most important step.
how to create manifest file for an Executable jar file
Create a manifest file. Save manifest file using the extension .txt using the text editor and input the following:
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.
use launch4j to package up the jar into an EXE.
Although launch4j has a command-line interface, I first used the GUI.
The first screen I filled in looked similar to this:
I tried to just save the EXE at that point, but I then needed to specify a minimum Java version on this tab:
output file heyguys.exe is your output file name
Java Launcher
Java Launcher run Java applications and applets by double-clicking class files; view class source codes and class hierarchies in graphic format by right-clicking;
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.
A LAX Executable is an executable file that is used to launch a Java application on any LaunchAnywhere-compatible platform. Currently, InstallAnywhere creates LaunchAnywheres on Windows 95/98/NT/2000/Me, Solaris, Linux, and Mac OS X. LaunchAnywhere enables end-users to double-click on an icon (Windows or Mac OS X) or type a single command (UNIX) to start a Java application
To get executable .exe file we must convert .class file to .jar
How to convert .class file to .jar
Create the JAR file. The format of the command line for creating the JAR file looks like this:
"jar cf yourjarfilename manifest.txt Smile.class"
- The "jar" portion refers to the jar.exe program, which compiles the JAR file.
- The "c" option specifies that you want to create a JAR file
- The "f" option means that you want to specify the filename.
- The "yourjarfilename" portion is where you should type the name that you want the file to have.
- For example, you might type "jar cf myjar manifest.txt myclass.class." This would create a JAR file with the filename "myjar.jar" which would include the files "manifest.txt" and "Smile.class."
- If you add directories to the JAR file, the jar.exe utility will automatically add their contents
If you want to create executable .exe file of your .class file of java then you have to convert it into
jar (Java ARchive) file this is most important step.
how to create manifest file for an Executable jar file
Create a manifest file. Save manifest file using the extension .txt using the text editor and input the following:
- Main-Class: Smile(or whatever your file's name is )
Creating an Executable jar File By Software
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.
Once you have downloaded JSmooth, open the application.
Specify the skeleton of the executable application. In my case I want to create a Console wrapper that will run on the command prompt console.
Give the full path to the .jar file by selecting the option “Use an embedded jar”. Go to Application tab and set the Main Class file. Put the same name which you had used in Eclipse project as Main Class.
Go to the Executable tab and set
Executable Binary file path. Mention the full path with name of the .exe
file that you want to be created. One can also provide an icon for the
executable file.
Now, go to the JVM Selection tab. Specify the minimum and maximum JVM versions required to run your application.
Finally, go to the Project menu and compile the file. If there are no compilation errors then you should see the .exe file generated in the specified directory.
Launch4j
Launch4j is a cross-platform tool for wrapping Java applications distributed as jars in lightweight Windows native executables. The executable can be configured to search for a certain JRE version or use a bundled one, and it's possible to set runtime options, like the initial/max heap size. The wrapper also provides better user experience through an application icon, a native pre-JRE splash screen, a custom process name, and a Java download page in case the appropriate JRE cannot be found |
Although launch4j has a command-line interface, I first used the GUI.
The first screen I filled in looked similar to this:
I tried to just save the EXE at that point, but I then needed to specify a minimum Java version on this tab:
output file heyguys.exe is your output file name
Java Launcher
Java Launcher run Java applications and applets by double-clicking class files; view class source codes and class hierarchies in graphic format by right-clicking;
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.
LaunchAnywhere
A LAX Executable is an executable file that is used to launch a Java application on any LaunchAnywhere-compatible platform. Currently, InstallAnywhere creates LaunchAnywheres on Windows 95/98/NT/2000/Me, Solaris, Linux, and Mac OS X. LaunchAnywhere enables end-users to double-click on an icon (Windows or Mac OS X) or type a single command (UNIX) to start a Java application
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
orC:\mywork> jar cvfe Craps.jar Craps *.class
- Test your jar:
C:\mywork> Craps.jar
orC:\mywork> java -jar Craps.jar
Creating a jar File in Eclipse
In Eclipse Help contents, expand "Java development user guide" ==>
"Tasks" ==> "Creating JAR files."
Follow the instructions for "Creating a new JAR file"
or "Creating a new runnable JAR file."
The JAR File and Runnable JAR File commands
are for some reason located under the File menu:
click on Export... and expand the Java node.
Creating a jar File in JCreatorYou can configure a "tool" that will automate the jar creation process. You only need to do it once.
manifest.txt or copy
and edit an existing one.
Place manifest.txt in the same folder
where the .class files go.
Under View/Toolbars
check the Tools toolbar.
Click on the corresponding tool button or press Ctrl-1
(or Ctrl-n if this is the n-th tool)
to run the Create Jar File tool.
With Windows Explorer, go to the jar file that you just created and double click on it to run. |