Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Java executables on Windows 10 machines by example

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:

  • There will be the JAR/EXE as mentioned above, lets call it myapp.exe (built from myapp.jar)
  • The app will output logs to a (local?) directory, myapp.log
  • The app will load a config file at runtime, myapp.properties
  • The distribution should also contain the User's Guide, 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:

  1. Removing the old version (and all of its other artifacts such as the log file, config/properties file, user guide, etc) off the machine completely
  2. Installing the new version at either the Windows 10 default location, or allowing the user to specify a different location

Additionally, if at all possible, I'd like the installation process to include:

  1. A requirements check for things like minimum memory and disk space, OS version info/compatibility (i.e. make sure its being installed on Windows 10, etc.)
  2. Provide an easy-to-use wizard such as an MSI that the user can click though
  3. Optionally install shortcuts to the user's Desktop

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:

  1. Save the ZIP to some place on the user's machine, say, the Desktop
  2. Move the previous app and its artifacts to the trash, manually
  3. Unzip the new ZIP

However that feels janky and I'm looking for something more professional. Any solutions here?

like image 520
hotmeatballsoup Avatar asked Nov 14 '19 17:11

hotmeatballsoup


People also ask

How to run a Java program in Windows 10?

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 ...

How do I create an EXE file from a Java program?

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.

How do I install Java on Windows?

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:

How to setup Java environment in Windows 10?

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.


1 Answers

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

like image 100
Eng.Fouad Avatar answered Oct 23 '22 01:10

Eng.Fouad