1

我一直在关注http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/tutorial.html上的休眠教程

正如其他人在各种网络板上指出的那样,它是不完整的。当我运行这个命令时:

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

这里还有什么问题?

谢谢!

4

2 回答 2

0

I think your classpath is wrong. Try

set CLASSPATH=C:\Users\robe\Documents\hibernate\project1\src\main\java

You don't need the org. That is part of the full qualified class name. The full class name is org.hibernate.tutorial.EventManager

I am not familiar with this tutorial's problem. You may get other classpath errors. If you do you can add more to the class path by separating them by a semi colon.

Also you are setting the classpath in the cmd line. It will only be set for that session so you will have to run your mavem command in the same one. Or set it in your global environment variables

于 2012-09-30T21:25:27.120 回答
0

Try running:

mvn clean install

I know it sounds obvious, but when I tried to execute

mvn exec:java -Dexec.mainClass="org.hibernate.tutorial.EventManager" -Dexec.args="store"

I get the same error as you did. But after running mvn clean install the app started (I ran clean install for this code https://github.com/stivlo/hibernate-tutorial, it looks it is the same thing)

于 2012-09-30T21:29:21.553 回答