我一直关注http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/tutorial.html
上的hibernate教程正如其他人在各种网页上指出的那样,它是不完整的。 当我运行此命令时:
mvn exec:java -Dexec.mainClass =“org.hibernate.tutorial.EventManager”-Dexec.args =“store”
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building First Hibernate Tutorial 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ hibernate-tutorial >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ hibernate-tutorial <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ hibernate-tutorial ---
[WARNING]
java.lang.ClassNotFoundException: org.hibernate.tutorial.EventManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:722)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.962s
[INFO] Finished at: Sun Sep 30 17:03:34 EDT 2012
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (d
efault-cli) on project hibernate-tutorial: An exception occured while executing
the Java class. org.hibernate.tutorial.EventManager -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception
所以我认为问题很明显。当maven执行java时,java不知道在哪里可以找到我的'EventManager'。我在命令行上尝试了以下内容:
设置CLASSPATH = C:\ Users \ robe \ Documents \ hibernate \ project1 \ src \ main \ java \ org
这里还有什么可能是错的?
谢谢!
答案 0 :(得分:0)
我认为你的类路径是错误的。尝试
set CLASSPATH=C:\Users\robe\Documents\hibernate\project1\src\main\java
您不需要组织。这是完全限定类名的一部分。完整的类名是org.hibernate.tutorial.EventManager
我不熟悉本教程的问题。您可能会遇到其他类路径错误。如果这样做,可以通过用分号分隔它们来为类路径添加更多内容。
您还要在cmd行中设置类路径。它只会为该会话设置,因此您必须在同一个会话中运行mavem命令。或者在全局环境变量
中设置它答案 1 :(得分:0)
尝试跑步:
mvn clean install
我知道这听起来很明显,但是当我试图执行时
mvn exec:java -Dexec.mainClass="org.hibernate.tutorial.EventManager" -Dexec.args="store"
我得到了和你一样的错误。但是在运行mvn clean install后,应用程序启动了(我为这段代码https://github.com/stivlo/hibernate-tutorial运行了干净安装,它看起来是同样的事情)