In this blog post, I will explain how to use the jpackage tool that is provided with Java to (1) package the JAR file of SPMF into an EXE file for Windows, and (2) to create an installer for SPMF.
Requirements
It is necessary to have:
- A computer with Windows (as I will give instructions for this platform, but you may do something similar on other operating system)
- A recent version of the Java JDK (at least version 14) so that you have the jpackage command available.
- The JAR file of SPMF. You can download it here: spmf.jar or from the website of SPMF.
- The ICO file of SPMF (if you want to make an application that has an icon): SPMF.ico
How to create an EXE application of SPMF for Windows
Step 1. On a windows computer, create two folders /input/ and /output/ on the desktop.
Step 2. Put the files spmf.jar and SPMF.ico in the folder /input/ that you have just created.
Step 3. Open the command line of Windows and execute this command:jpackage --input C:\Users\philippe\Desktop\input\ --dest C:\Users\philippe\Desktop\output\ -n “SPMF” --main-jar spmf.jar --main-class ca.pfv.spmf.gui.Main --type app-image --icon C:\Users\philippe\Desktop\input\SPMF.ico
where C:\Users\philippe\Desktop\ should be replaced by the path to your desktop on your computer.
After executing this command, an EXE file will have been created in the output directory \output\
Step 4. To launch the software, you can now click on SPMF.exe.
How to create an installer for SPMF for Windows?
You can follow the same steps as above but use this command:
jpackage --input C:\Users\philippe\Desktop\input\ --dest C:\Users\philippe\Desktop\output5\ -n “SPMF” --main-jar spmf.jar --main-class ca.pfv.spmf.gui.Main --type exe --icon C:\Users\philippe\Desktop\input\SPMF.ico --win-dir-chooser --win-menu --win-shortcut-prompt
Then, this will create an installer, which looks like this:
This is the installation process on Windows 11:
And those are the files after installation:
Customization and generating installers for other platforms
There are also many other options offered by jpackage, including generating packages for other platforms. For more information see the documentation of the jpackage command.
Conclusion
This was just a short blog post to show how to package SPMF.jar into a native application. I think the process of using jpackage is quite simple. In the past, I had used some other commercial tools to create EXE files for Java programs but the process was more complicated. I am thus happy to have found jpackage.
—
Philippe Fournier-Viger is a distinguished professor of computer science