0

I have created a jar file in eclipse using maven and am able to run a class from the jar file with eclipse. However when I run the following command from the command prompt:

c:\recomendation_engine\recomendation\target>java -classpath recomendation-0.0.1
-SNAPSHOT.jar recomendation.ManageGeneralContent test

I get the following error:

Organization Environment test
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(Unknown Source)
        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.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at recomendation.ManageGeneralContent.main(ManageGeneralContent.java:52)

I believe that the issue is that the class can not find the mysql driver. However it is in the classpath:

c:\Program Files\Java\jdk1.7.0_60\lib\*;C:\Users\User\.m2\repository\com\google\
guava\guava\18.0-rc1\guava-18.0-rc1.jar;C:\Users\User\.m2\repository\org\slf4j\s
lf4j-api\1.7.7\slf4j-api-1.7.7.jar;C:\Users\User\.m2\repository\com\jolbox\bonec
p\0.8.0.RELEASE\bonecp-0.8.0.RELEASE.jar;C:\Users\User\.m2\repository\postgresql
\postgresql\9.1-901-1.jdbc4\postgresql-9.1-901-1.jdbc4.jar;c:\recomendation_engi
ne\recomendation\lib\mysql-connector-java-5.1.6.jar;C:\recomendation_engine\reco
mendation\target\recomendation-0.0.1-SNAPSHOT.jar;

Can you please tell me what I am doing wrong?

1
  • Since Java 6, it has not been necessary to load JDBC drivers with Class.forName. Simply placing the driver in the classpath is sufficient. Commented Apr 21, 2016 at 21:06

1 Answer 1

1

You are overriding the CLASSPATH environment variable when you specify the "-classpath" switch on the java command line.

Try running:

c:\recomendation_engine\recomendation\target>java 
    recomendation.ManageGeneralContent test

Check out: http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! If you like, please take a moment to give my answer the checkmark.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.