exe4j: detailed tutorial for converting jar package into exe application

Posted by scialom on Wed, 05 Jan 2022 20:34:42 +0100

1. Foreword

Requirements encountered in recent work: it is required to make a desktop application, which is used to connect the Linux system and has operation and maintenance function. It is required to run win and operate through the interface, but the interface is not required to be very beautiful.

Since I mainly focus on Java and am relatively familiar with the back end, I learned through a search:

  1. First, Java development GUI is not the mainstream
  2. In the history of Java GUI development, the first stage is awt, the second stage is swing and swt, and the third stage is JavaFX. Therefore, JavaFX is selected for development.
  3. After the jar package is completed, you want to package it as exe.

Assuming that the jar package has been written, the problem we will encounter is how to package the jar package into an exe application, so as to provide others with support for operation and maintenance operations, and to solve the problem that there is no jre environment on the on-site win.

After a search, we found that exe4j can be used as a tool. This article introduces the installation and use of exe4j to complete the conversion from jar package to exe application.

2. Prepare


  1. A jar package that has been completed and can be started normally.
  2. exe4j, a tool that can convert jar into exe, can be installed and activated according to the following steps.

3. Installation and activation of exe4j


  1. Download address: https://www.ej-technologies.com/download/exe4j/files

    Enter the website, select the required version, and click download. Note that exe4j 6.0 requires jdk version 1.8 and above.

    The download is very simple. Basically, it can be done directly in the next step.

  2. After installation, run the software and click Enter License.

    Just fill in the user name and company, and just copy one under the registration code.


4. Steps to package jar into exe


  1. Select "JAR in EXE" mode to proceed to the next step.

  2. Enter the application name (the name of the packaged program) and the output path (the path saved by the packaged program), and click next.

  3. When "GUI application" is selected, the name of the exe running program must be filled in, and the icon path can be ignored. The option of "only one program can be run on the computer" is not checked here.

  4. Click Advanced options, select "Redirection", do not modify the default error log output path, and click next.

  5. Click Next directly on the Service options page and next directly on the Version Info page.

  6. If it is a 64 bit operating system, you need to check it and click next.

  7. Click Next directly on the Manifest options page.

  8. Import the jar you want to convert into exe and all dependent jar packages in the project.

  9. Add the running main class and click next.

  10. Configure the JRE version and select "Search sequence" in advanced options.

  11. Copy the local jre to the exe output path for subsequent use by others without jre environment, and click "+" to add the local jre

    • This directory is the output path I configured in step 2.

    • The picture above shows my local jre directory

    • Add the local jre, where you can directly use the relative path, that is, the jre under the current directory

    If this step is not configured, exe will report an error on other people's computers and prompt that the class cannot be found, as follows:

    java.lang.NoClassDefFoundError: javafx/application/Application
    	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
    	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
    	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
    	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
    	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
    	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
    	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    	at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:80)
    	at com.exe4j.runtime.WinLauncher.main(WinLauncher.java:94)
    Caused by: java.lang.ClassNotFoundException: javafx.application.Application
    	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    	... 11 more
  12. Move the added jre up to the top of the queue and click next.

  13. Select "Client HotSpot VM" and click next.

  14. Click Next directly on the next two pages.

  15. exe conversion is completed. You can find it in the output directory and double-click to run it.

  16. After the test is successful, you can package exe together with jre to other people's computers to test whether it can run. If you can, it's done!

Please leave a message or send a private letter if you have any questions during use!

Topics: Java jar javafx