wood burning stoves
The moose likes Ant, Maven and Other Build Tools and the fly likes ClassNotFoundException: com.mysql.jdbc.Driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "ClassNotFoundException: com.mysql.jdbc.Driver" Watch "ClassNotFoundException: com.mysql.jdbc.Driver" New topic

ClassNotFoundException: com.mysql.jdbc.Driver

Hector Pertierra

Joined: Jun 06, 2006
Posts: 25
Hi everybody

I have a BIG problem with my ANT buildfile. I'm trying to run a simple Test to connect to my app's database, but after it succesfully COMPILES and JARS itself, when it gets to EXECUTE I get the following message:

[java] org.dotcom.contab.proceso.DAOException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
[java] at org.dotcom.contab.proceso.impl.MySQLDAOFactory.<init>(Unknown Source)
[java] at org.dotcom.contab.proceso.DAOFactory.getDAOFactory(Unknown Source)
[java] at org.dotcom.contab.salida.Main.main(Unknown Source)
[java] Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
[java] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
[java] at java.lang.Class.forName0(Native Method)
[java] at java.lang.Class.forName(Class.java:164)
[java] at org.dotcom.contab.proceso.impl.MySQLDAOFactory.loadDriver(Unknown Source)

I know I probably have a problem with the CLASSPATH, since I'm running the app directly from the jar archive: here's the code:

I'm really really stuck, I've tried a bunch of things and I don't know what to do anymore. I read somewhere that when running a program from the jar it ignores user classpath settings, is it true??? I NEED to run it from the jar since it's one of the projects requirements...


Thanks in advance

I'd be useless without Head First books...
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
I notice that you seem to be putting third party jars into your jar file. Those other jars will *not* automatically be on the classpath!

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Hector Pertierra

Joined: Jun 06, 2006
Posts: 25
Yeah, I'm aware of that, but how do I PUT them into the classpath???
Hector Pertierra

Joined: Jun 06, 2006
Posts: 25
After fighting with the CLASSPATH for more than 24 hours, I fixed it

I had to put the JAR File next to the distribution. And set the Manifest's Class-Path to the JAR File. It finally worked. Thanks!
prateek urmaliya
Ranch Hand

Joined: Sep 15, 2006
Posts: 87
May be It's too late
but you can try

this message brought to you by .... PIE! .... it's yummy! ;)
I agree. Here's the link: http://aspose.com/file-tools
subject: ClassNotFoundException: com.mysql.jdbc.Driver
It's not a secret anymore!