How to solve "java.lang.ClassNotFoundException: java.sql.SQLException" after converting to .exe

458 Views Asked by At

I developed a todo list project based on JavaFX on IDEA, which can run well on the IDEA.

And the database that I use is Firebird (2.5.9).

When I package the project into a jar, and use 'exe4j' to package the jar into an exe file, and execute it, the following problems arise:

java.lang.NoClassDefFoundError: java/sql/SQLException
    at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3434)
    at java.base/java.lang.Class.getDeclaredMethod(Class.java:2705)
    at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:82)
    at com.exe4j.runtime.WinLauncher.main(WinLauncher.java:94)
Caused by: java.lang.ClassNotFoundException: java.sql.SQLException
    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:521)
    ... 5 more

I tries the solution following, but I think it is not completely suitable to my problem. https://stackoverflow.com/questions/73222789/noclassdeffounderror-java-sql-sqlexception-error-postgres-hibernate

And I want that my project can be executable under .exe, that's what I want to do.

1

There are 1 best solutions below

0
Mafei On

The error is happening due to the Java Module in JDK 17. You have to mention the required packages that you want to use in the project in the module-info.java file like below.

module org.zoftstack.redpos.lite.redposlite {
    requires javafx.controls;
    requires javafx.fxml;

    //requires these packages
    requires java.sql;
    requires mysql.connector.j;
    

    ...
}