Generate Windows EXE installer setup/EXE executable file from executable JAR file using javapackager of JAVA8 JDK

Java

Generate Windows EXE installer setup/EXE executable file from executable JAR file using javapackager of JAVA8 JDK

For all those who are dealing with executable JARs of technologies like SWING or any other standalone applications. Yup distributing files like these are very hefty jobs. Well if you are planning to distribute an installer file or executable file(Both EXE) for WINDOWS machine let me give a pretty basic solution for it.

Since JDK8 Java ships with javapackager.exe file that is used to create these installer EXE or executable EXE files. Before doing anything make sure your machine has JDK8, INNO SetUp5 http://jrsoftware.org/ and WIX tool https://wix.codeplex.com installed on it.Let’s start with EXE executable file:-

javapackager -deploy -native -outdir packages -outfile sample -srcfiles your.jar -appclass com.sample.YourMainClass -name “Sample” -title “Sample App”

This script is run on command prompt and make sure your javac is pointing to JDK8. Navigate to the directory where your executable JAR lies and run this script. I guess everything is very much understandable here. Since we have not provided any type to our native argument so by default it will create a EXE executable file, a ready to go launcher. However if your requirement is to create a installable application then you need an EXE installer setup file. Just execute below script:-

javapackager -deploy -native exe -BshortcutHint=true -Bvendor=SampleVendor -outdir packages -outfile sample -srcfiles your.jar -appclass com.sample.YourMainClass -name “Sample” -title “Sample App”

This script will create an EXE set up file, just double click it and install your application. Note, your application is installed in Users-> user home directory -> AppData -> Local directory. Here -BshortcutHint will create a shortcut icon on the Desktop after successful installation. The best part about javapackager is that it ships with JRE so even if the target machine does not have JRE installed there wont be a problem. However if you want your application to get installed in Program files directory just add -BsystemWide=true to the our above script. But installing in Program files has some permission issues so if you can deal with that then no probs go for it, otherwise go ahead with AppData->Local directory. For more info visit:-

https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javapackager.html

About Anoop Kumar Rai