Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Jar run error

Hello i'm new here on this forum so excuse me if i do something wrong.

I have a question for a time i program in java my first real project is at a beta fase but when i compile him to an jar file and run him with the following :
java -jar project.jar

i get an error (This one):

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Reparatie.Main.<init>(Main.java:34)
at Reparatie.Main.main(Main.java:46)

I use an mysql driver manager (mysql-connector-java-3.1.12-bin.jar).
I program in Netbeans IDE 4.1

But i don't know why i get this error when i run my program in netbeans he runs correctly.

Can anyone help me please ! :(

If you need some code to help please ask...

Greetz ,

Pielie
[1403 byte] By [pielie] at [2007-11-11 8:46:58]
# 1 Re: Jar run error
is the mysql jar file included in the same directory as your project jar? If not, then is listed anywhere in your classpath or in your jsdk extensions directory?

I'm guessing the mysql jar isn't included in a classpath anywhere. It works when running from Netbeans because it automatically sets the classpath when you compile to include any extra jar files you've set it up with.

Include "mysql-connector-java-3.1.12-bin.jar" in the same directory where you're running your project jar from and it should run.
Phaelax at 2007-11-11 22:34:22 >
# 2 Re: Jar run error
sorry i tried that also but it won't work, i also tried the command in cmd set classpath="path to jar file" but also that doesn't seems to work
pielie at 2007-11-11 22:35:22 >
# 3 Re: Jar run error
there are several methods to enshure your classpath:
easy but dirty is to put the mysql jar into the ext-folder of your jre and java installation folders. then java will definitely find it.
better is to use the classpath in the java command:
java -cp ".;mysql.jar;project.jar" -jar project.jar
if youre using windows, you cann set your classpath in system/systemvariables
graviton at 2007-11-11 22:36:26 >