Creating an executable file with Launch4J and Java 11

How to build an executable file for a Java 11 GUI application using Launch4J

Before we look at the how we should ask why.  The aim is to package up our Java application so that we can distribute it to others. We want them to be able to launch the application without having to install anything else.

Therefore, we are looking to deliver our Java application along with the Java Runtime Environment and any external libraries required for it to run. To do this needs a few tools:


Assuming you have Java 11 installed on your machine and it is the default Java installation, you will have issues trying to run the Launch4J executable program as installed.  To run “Launch4J”, open a cmd prompt, go to the directory where you have installed Launch4J, type “java -jar launch4j.jar”, and press enter.

The Lanch4J application will open.

Launch4J default screen
Launch4J default screen when launched

On the Basic tab

To specify an output file, I used “C:\Temp\sun2\sun.exe”.

Specify the location of the JAR file. I used “C:\Temp\sun2\app2\sunlounger.jar” I chose to use an icon for my application, but this is optional. I used “C:\Temp\sun2\sunbed.ico”.

Launch4J populated basic tab
Launch4J Basic tab populated with values required for the example

On the Header tab

Make sure the Header type radio button for GUI is selected

Launch4J Header with settings for GUI
Launch4J Header tab with settings for the example application

On the JRE tab

Specify the Bundled JRE paths. I used “fxjre”.
Specifying the JRE path does not package the JRE into the executable file; the executable file will look for a folder called “fxjre” relative to where the executable file resides, and this should contain the JRE.

Specify the Min JRE version. I used 11.0.2.

Launch4J JRE tab with basic settings
Launch4J JRE tab populated with values for the example application that uses a Java 11 JRE

That’s all you need to do. Press the gear icon to build the executable file.

Folder contents after running Launch4J
Image of a folder contents after running Launch4J to build the executable file

To check your application runs, double-click the sun.exe file, and the application should launch.

Sunlounger application screen
Sunlounger application screen displayed after running sun.exe

However, you have JDK 11 installed on your machine, so this is not a valid test.  Ideally, you need a machine that does not have Java 11 installed and test it on that machine.

To deploy to another machine, you will need to install

  • Sun.exe
  • Folder fxjre

The fxjre folder contains the JRE your application requires to run; add this to the target machine with the executable file.  Do not change the folder name.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.