[英]exec-maven-plugin is giving class not found exception
I have a java class HelloWorld.java
, with a main method which prints "Hello world". 我有一个Java类HelloWorld.java
,其主要方法可打印“ Hello world”。
To execute this class via POM.xml I am using exec-maven-plugin
. 要通过POM.xml执行此类,我正在使用exec-maven-plugin
。
I implemented it using it's official documentation here http://www.mojohaus.org/exec-maven-plugin/usage.html like this: 我使用http://www.mojohaus.org/exec-maven-plugin/usage.html的官方文档来实现它,如下所示:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.demo.printTest.HelloWorld</mainClass>
<arguments>
<argument>argument1</argument>
</arguments>
<systemProperties>
<systemProperty>
<key>myproperty</key>
<value>myvalue</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
<plugin>another plugins</plugin>
</build>
I have tried to run via following commands, but it is failing on each command: 我试图通过以下命令运行,但每个命令均失败:
java.lang.ClassNotFoundException: com.demo.printTest.HelloWorld
mvn exec:java java.lang.ClassNotFoundException: com.demo.printTest.HelloWorld
Am I doing something wrong? 难道我做错了什么? I have already gone through post here Maven Run Project 我已经在这里发布过Maven Run Project
Is your code compiled to target/classes/ ? 您的代码是否已编译为target / classes /? If not your are maybe missing the maven compile phase? 如果不是,您可能错过了Maven编译阶段? When you call mvn exec:java you are not goint to the mvn lifecycle and the java source is not compiled so your exec cant find the class. 当您调用mvn exec:java时,您不会进入mvn生命周期,并且未编译Java源代码,因此您的exec无法找到该类。
Try to do a mvn compile first before you exec. 在执行之前,请先尝试执行mvn编译。
Edit: See the correct answer here: How do I execute a program using Maven? 编辑:在这里看到正确的答案: 如何使用Maven执行程序?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.