I imagine some Java gurus with experience delivering Java apps on Windows desktops will be able to ace this one. I've always been a Mac/Linux Java developer so this is uncharted territory for me :-/.
I have to write a Java 8 Swing application and install it on a Windows 10 (64-bit) machine. My gameplan is to package the app as an executable JAR and wrap it with Launch4J, so that it looks like a native Windows EXE (.exe file). However its a little bit more complication than that when it comes to the distribution:
myapp.exe
(built from myapp.jar
)myapp.log
myapp.properties
MyApp User Guide.html
Let's assume a Java 8 JRE/JDK is already installed on the machine, so we don't need to worry about installing Java itself.
The installation process must be simple and include:
Additionally, if at all possible, I'd like the installation process to include:
Given all this, I'm wondering what my options are in the modern Windows 10/Java/Launch4J landscape. Are there tools that will help me script together MSIs quickly, or do I have to write my own in, say, C#/.NET and have that be a separate binary/project? If MSIs aren't an option, what options exist that might hit all my bullets above?
I realize I could just distribute the whole thing as a ZIP, and have the installation process look something like:
However that feels janky and I'm looking for something more professional. Any solutions here?
How to run a Java program in Windows 10. To run a java program in Windows 10, we need first to install Java and then set up the environment variables. To do this, follow the following steps-How to install Java? Step 1) Visit the oracle website and then click on download. Step 2) Now, on the next page, click on Accept License Agreement and ...
To make the exe file for above java program, run maven command: mvn package. Above command will create the “howtodoinjava.exe ” file in your project’s target folder. Double click on .exe file will open the window like this. Launch4j maven demo to create java executable.
For instance, Oracle offers two options to install Java on Windows: through a .zip file and a .exe executable file. Next up, let’s choose the Windows x64 Installer option:
Click on Environment Variables, go to system variables, and double click on Path. Now add the path of the bin file present in the JRE folder and the JDK folder to the Path variable. The JRE and JDK are by default, present in the Java folder of Program Files. The setup of the Java environment is complete.
JDK 8 is bundled with a tool called javapackager
(formerly javafxpackager
) which is part of JavaFX. However, you can use it package java swing application without using JavaFX. This tool can generate an installer file (exe
or msi
) which contains the application and the Java runtime as well.
Here is an example:
javapackager -deploy -native exe -Bruntime="C:\Program Files\Java\jdk1.8.0_66\jre" -Bicon=app_icon.ico -BsystemWide=true -BshortcutHint=true -outdir packages -outfile appFile -srcdir dist -srcfiles MyApp.jar;COPYING.txt -appclass somePackage.MainClass -BlicenseFile=COPYING.txt -name appName -title "The application name"
For more information, see adding icon to bundle using javapackager
There is also a new tool called jpackage
which is based on javapackager
. It is proposed to be released with the next JDK release, JDK 14. Note that javapackager
was removed from JDK since version 11 as part of the removal of JavaFX.
See A Brief Example Using the Early Access jpackage Utility
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With