Once we have a JAR, we can create a self-containing application using the -deploy command with the -native parameter:
"$JAVA_HOME/bin/javapackager" -deploy -native -verbose -appclass chapterEleven.SimpleApp
-outdir dist-native -outfile SimpleApp
-srcdir dist -srcfiles SimpleApp.jar
-appclass chapterEleven.SimpleApp -name SimpleApp
Parameters are similar to the JAR creation routine, but we need to provide a JAR here as a source.
javapackager may ask you to install additional software to run properly. For example, on Windows you'll need to have the following applications:
- WiX Toolset (http://wixtoolset.org/): Windows installer's tools
- Inno Setup (http://www.jrsoftware.org): Another installer's toolkit used to generate a .exe installer
This command will populate a dist-native folder with native executables (for example, .exe and .msi on windows) and Java runtime as a dependency for it:
If you run SimpleApp.exe from the SimpleApp folder, you'll directly run a JavaFX application even on a machine without Java installed.
The SimpleApp-1.0.exe and SimpleApp-1.0.msi files are installers that can set up a similar SimpleApp folder on any machine.
On Windows, the size of the resulting folder is 180 Mb. It seems too much for a 3 Kb JAR—but Java9 Jigsaw can help with this, as we will see in the next section.