views:

367

answers:

2

Hi all,

I have an token class file in an jar file. The token class files is the class that uses jdbc to retrieve data from the database. However when I call the jar file it does not seem to recoginize the external mysql driver jar file.

The error is pointed to this line Class.forName(driver);.

I have referenced the mysql driver in the ant build file and every classpath i could think of.

 <mkdir dir="build/server/dist"/>
 <jar destfile="build/server/dist/VNCOverHTTPServer.jar" basedir="build/server/classes">
  <manifest>
   <attribute name="Main-Class" value="jhttpserver.JHttpServer"/>
   <attribute name="Class-path" value="lib/servlet.jar lib/mysql-connector-java-5.1.7-bin.jar config/"/>
  </manifest>
 </jar>

Nothing is working? any help would be appreciated.

thanks

java.lang.ClassNotFoundException: mysql at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:316) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:288) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at socksviahttp.server.token.getConnection(token.java:58) at socksviahttp.server.token.exists(token.java:75) at socksviahttp.server.ServletSocks.doPost(ServletSocks.java:328) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at jhttpserver.JHttpServerThread.run(JHttpServerThread.java:217)

A: 

When you run your jar file, either by double-clicking it or from the command line):

java -jar VNCOverHTTPServer.jar

then at the directory where your jar is located, there should be a lib folder with the required jars. Is this the case?

Update: From your error report it is evident that you are using URLClassLoader to load the mysql class. Adding the jar file in the classpath won't help, you need to make the class available through a URL link.

kgiannakakis
yes the required jars are in the lib directory
Could you post the error trace?
kgiannakakis
just did thanks
how do i make the class available to through a URL link?
Why are you using URLClassLoader at the first place? This is complicated and only meant for special cases. If you are doing it through a library, consult its documentation.
kgiannakakis
+1  A: 

And the line registering the mysql driver is something along the lines of:

Class.forname("com.mysql.jdbc.Driver");

The class loader error seems to be for an unadorned 'mysql' class, not one referenced by package. You generally only see this error when you're dynamically loading a class without specifying the full class name.

What do you use to load the mysql driver class? if it's a spring config file, then you probably don't have the full class name in the config file.

And I just noticed the lower case 'Class-path'. It's supposed to be 'Class-Path'

Petesh
yea you are write, i had a database.properties file and at that had 2 versions, the generic one had values of 'mysql' throughout the fields. Case Closed