I'm using win10, openjdk-18.0.2 x64, mysql-connector-j-8.2.0 and Netbeans 15, building with Ant.
When I run from the IDE the SQL pieces are found and run fine. When I run with my installed java i.e. java -jar app.jar it runs fine. However I need to deploy this app on boxes that don't have java installed so it needs to run out of the JRE that gets created with the build. So if I run appJRE\bin\java -jar app.jar everything except the SQL methods work fine.
I have multiple jar files in my IDE classpath, and they all work in the executable except for the mysql-connector*.jar. I get a runtime error when I try to do anything with SQL. NoClassDefFoundError: on SQLException, DriverManager etc.
I have the mysql-connector*.jar file in my IDE classpath. And it is in the same dist/lib directory along with all the other jar files that I deploy with the executable. I've tried using the -Djava.libraries.path=dist\lib\mysql-connectors-j-8.2.0.jar switch when launching the executable but that doesn't help.
I tried adding my jar file names to the Manifest (suggested by ChatGPT). I found that if I added just the mysql jar file name then I get run time errors because none of the other jar files are found. When I add them all to the manifest, I only get an error for the sql jar.
I've read through all the similar questions on this site but none get me any farther.
If it were a conflict with versions, I would think I'd get an error when running in the IDE, but like I said, that runs fine. I'm out of ideas. If you have anything that can get me going I'd appreciate it.
Here's my manifest.
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.10.8
Created-By: 18.0.2+9-61 (Oracle Corporation)
Class-Path:
lib/jsch-0.1.55.jar
lib/javaee-api-8.0.jar
lib/AbsoluteLayout.jar
lib/jfreechart-1.5.3.jar
lib/mysql-connector-j-8.2.0.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: app
My app.jar is in the same directory as the lib directory, and the lib directory contains the mysql-connector-j-8.2.0.jar along with the other jars. My appJre is also in the same directory
12/13/2023 10:24 AM <DIR> lib
12/13/2023 08:35 AM 1,471,425 app.jar
12/13/2023 10:24 AM <DIR> appJre
And I've tried these commands to run it:
appJre\bin\java -jar app.jar
appJre\bin\java -cp .:lib/* -jar app.jar
The sql jar is recognized if I launch it with my installed java:
java -jar app.jar
But I need it to work with the deployable Jre.
The only difference between the two VMs that I can see is that my installed VM uses sharing:
Installed VM recognizes the sql classes
<installed>java -version
openjdk version "18.0.2" 2022-07-19
OpenJDK Runtime Environment (build 18.0.2+9-61)
OpenJDK 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing)
Deployable VM fails to find sql classes
appJre\bin\java -version
openjdk version "18.0.2" 2022-07-19
OpenJDK Runtime Environment (build 18.0.2+9-61)
OpenJDK 64-Bit Server VM (build 18.0.2+9-61, mixed mode)
Why do these behave differently? It's like the SQL library needs something in the SDK which isn't present in the JRE.
And here's a stack trace:
java.lang.NoClassDefFoundError: java/sql/SQLException
at controllers.GuiMan.init(GuiMan.java:137)
at controllers.MainFrame.init(MainFrame.java:181)
at controllers.MerlinLab.lambda$main$0(MerlinLab.java:43)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
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)
... 16 more