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?
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