Maven多模块

时间:2017-04-12 07:55:36

标签: java eclipse maven

我在我的项目中创建了两个模块。它已经编译但没有正确执行。所以帮助我解决这个问题。在这里,我还提供了完整的错误日志。 错误日志:

C:\workspace\multimaven>mvn exec:java -Dexec.mainClass="com.multimaven.module2.DerivedClass"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] multimaven
[INFO] module1
[INFO] module2
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building multimaven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ multimaven ---
[WARNING]
java.lang.ClassNotFoundException: com.multimaven.module2.DerivedClass
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:270)
        at java.lang.Thread.run(Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] multimaven ......................................... FAILURE [  0.375 s]
[INFO] module1 ............................................ SKIPPED
[INFO] module2 ............................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.734 s
[INFO] Finished at: 2017-04-12T12:56:43+05:30
[INFO] Final Memory: 9M/153M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project multimaven: An exception occured while executing the Java class. com.multimaven.module2.DerivedClass -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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 read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

1 个答案:

答案 0 :(得分:0)

这与maven多模块性质无关。您可能在编译之前运行插件。确保定义以下内容,

<plugin>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>exec-maven-plugin</artifactId>
     <version>1.2.1</version>
     <configuration>                 
         <mainClass>com.multimaven.module2.DerivedClass</mainClass>
     </configuration>
</plugin>

在运行插件之前,请执行以下操作,

mvn clean install然后mvn exec:java或者像你通过命令行一样。