简体   繁体   English

Java文件在Eclipse中运行,但在命令行中运行

[英]Java File runs in eclipse but on command line

I have created a jar file in eclipse using maven and am able to run a class from the jar file with eclipse. 我已经使用maven在eclipse中创建了一个jar文件,并且能够使用eclipse从jar文件中运行一个类。 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. 我相信问题是该类找不到mysql驱动程序。 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. 在Java命令行上指定“ -classpath”开关时,将覆盖CLASSPATH环境变量。

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 检出: http : //docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM