Java help - .jar unable to find MySQL driver

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
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
 

siftings81

Member
Sep 3, 2001
61
0
0
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.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
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.
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
Thank you, I'll try that out. If it doesn't work, I'll come back here and provide the gory details ... =)
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
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.