I'm using jpackage to create native Java installer on Windows. And also my app need a JDBC library (example mysql-connector-java-8.0.28.jar
) to run the native app to connect the database.
I'm using NetBeans to build the app and after build, I saw the mysql-connector-java-8.0.28.jar
are in dist/lib
directory.
So that's mean, if I run java -jar myProgram.jar
inside dist
directory, the app will refer the mysql-connector-java-8.0.28.jar
inside the lib
library.
The directory in my project be like this:
dist/
lib/mysql-connector-java-8.0.28.jar
myProgram.jar
This is the result after using jpackage and install the native app:
myProgram/
app/myProgram.jar
runtime/<the jre directory>
myProgram.exe
And I run the app, I got error that JDBC class not found:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/naming/NamingException
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:186)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
I'm using this command to create the installer:
jpackage \
--type exe \
--runtime-image minimal-jre \
--main-jar myProgram.jar \
--input target \
--win-console
So, my question is, how to bundle the lib
folder so that .exe
program can connect the JDBC class?
The documentation: https://docs.oracle.com/en/java/javase/14/docs/specs/man/jpackage.html