Create a Windows Executable for Java with Embedded JAR Files
May 27, 2009
The following is a quick tutorial on how to create a single executable for a java application using WinRun4J. We will also give it a splash screen.
To start download WinRun4J.
Now unzip it into any folder, create a new directory called winrun4j and copy:
You should now have a folder that looks like this:
Now create a console window and change directory to your winrun4j folder:
Now its time to use RCEDIT to embed the files into the WinRun4J executable. If you run RCEDIT you should see the following output:
F:\winrun4j>RCEDIT.exe WinRun4J Resource Editor v1.0 (winrun4j.sf.net) Edits resources in executables (EXE) and dynamic link-libraries (DLL). RCEDIT [resource] filename Specifies the filename of the EXE/DLL. resource Specifies the name of the resource to add to the EXE/DLL. /I Set the icon as the default icon for the executable. /A Adds an icon to the EXE/DLL. /N Sets the INI file. /J Adds a JAR file. /E Extracts a JAR file from the EXE/DLL. /S Sets the splash image. /H Adds an HTML file the EXE/DLL. /C Clears all resources from the EXE/DLL. /L Lists the resources in the EXE/DLL. /P Outputs the contents of the INI file in the EXE. F:\winrun4j>
So to embed the JAR files we need to run the following command:
F:\winrun4j>RCEDIT.exe /J WinRun4J.exe WinRun4J.jar
F:\winrun4j>RCEDIT.exe /J WinRun4J.exe WinRun4JTest.jar
Now we need to edit the WinRun4J.ini file to contain the necessary instructions (or in this case remove the unnecessary ones). After editing it should look like this:
Now we are ready to embed this file into the executable:
F:\winrun4j>RCEDIT.exe /N WinRun4J.exe WinRun4J.ini
The last thing we want to do is embed the splash screen:
F:\winrun4j>RCEDIT.exe /S WinRun4J.exe SplashScreen.gif
You should see that the WinRun4J.exe file has increased in size:
You should now be able to double click on the WinRun4J.exe and launch the java application:
To check that there are no magic tricks you can delete the other files (i.e. WinRun4J.jar, WinRun4J.ini, SplashScreen.gif, WinRun4JTest.jar and RCEDIT.exe). You only need the executable.
That’s all folks.