• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java help - .jar unable to find MySQL driver

mundane

Diamond Member
Trivial problem, but the unexpected behavior is frustrating.

I have an application which requies a connection to a MySQL database. It's extremely happy if the mysql-connector-java-..-.jar file is in $JAVA_HOME/jre/lib/ext. Unfortunately, as Java is updated the above path points to a new, different directory, not housing said .jar file.

My thoughts on preventing this from happening were to place the connector within a directory and have the CLASSPATH point to it. My application, a .jar file itself, doesn't recognize the CLASSPATH, either as a system variable or through the command line (java -cp ... ). When the connector is not present within the ext directory, all attempts to provide its location through classpath are not acknowledged.

I wrote a very small class to test this issue - it just loads the driver and reports if it can be found. And it DOES obey the classpath, and can find the connector when the CLASSPATH is accurate (when the connector is not in the expected ext directory, which my jar file can't).

My program is an eclipse project, exported into a jar file. It is deployed on a SuSE machine. Current Java version is 1.4.2.10. Any hints on why the driver can't be found using Classpath when executing a [my] jar file?

Thanks,
Josh
 
I had the same issue before and the way I solved it was to add the following to the MANIFEST file:
Class-Path: mysql-connector-java-3.0.15-ga-bin.jar
Worked for me, although the jar file for your application has to be in the same directory as the driver.
 
You're gonna have to give exactly the commands that you use to start up your app, with the -cp flag and all. Then we can guess.

Sifting's suggestion should work too. You should be able to put the mysql jar in any directory, so long as the Class-Path: line points to it.
 
Thank you, I'll try that out. If it doesn't work, I'll come back here and provide the gory details ... =)
 
Thanks for the help. Modifying the manifest file enabled the application to find the connector. Looking around online, I found what I Suspected:
If you use -jar on the java.exe command line, java.exe will quietly ignore the set environment classpath and any -classpath or -cp command line options.
That explaines my difficulties.
 
Back
Top