Search code examples
javaspring-bootinstall4j

Install4j Installation of Java Jar Application Encounters Run Time Error of ClassNotFoundException


I am using the latest Install4j (Multi-Platform Edition 10.0.7 - build 10124). I have created a simple installation for a Java application utilizing the created .jar file from the project.

All the necessary installed files (including the .jar and resource files) are in a single application directory. Install4j is directed to this directory in the Files section of the application. A launcher was created for a console application. Under Java Invocation:

  • NO VM Parameters are utilized
  • The "Class path" option is selected, and the .jar file from the application is added as the classpath entry The main class form was selected as "Class path."... the field was populated with the classpath defined in my Spring Boot project. (The Select Main Class option shows a classpath version with BOOT-INF.classes.{rest of class path} in the droop-doughnut. This never seems to work, so the BOOT-INF.classes. portion is removed to leave the traditional {rest of class path})
  • A single argument is passed to designate the active profile (--spring.profiles.active=staging)

The media type is Windows 64-bit, and the JRE is Amazon Corretto - 17/17.0.7.7.1

The Build is completed successfully and creates a working installer application.

The installation was completed successfully, and the necessary files were added as expected.

The issue comes when we try to run the EXE file that Install4j creates for the Java Jar file application.

The application returns the following error message:

java. lang.ClassNotFoundException: {entered class path in Install4j application}
    at java. base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java. base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java. base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:80)
    at com.exe4j.runtime.WinLauncher.main(WinLauncher.java:94)
    at com.install4j.runtime.launcher.WinLauncher.main(WinLauncher.java:25)

Ironically, the application runs correctly with the java -jar command line argument, but the created EXE file does not execute successfully.

I have rebuilt my project, ensuring the classpath in question is defined in the manifest file and utilizing the many options within the Java Invocation screen of the Launcher setup screen.

Nothing has created a successful running EXE after installation of the application. In ALL examples, the application can be run from the command line but never from the EXE.

Has anyone had this same issue? Did you find a solution or a workaround?


Solution

  • You are using the wrong main class. Your actual main class is not on the class path, it is loaded by Spring Boot with its own class loader.

    Look at the META-INF/manifest.mf file, the main class in there will be

    org.springframework.boot.loader.JarLauncher
    

    You have to select that in the install4j launcher configuration.