Reputation: 4487
I have a java class HelloWorld.java
, with a main method which prints "Hello world".
To execute this class via POM.xml I am using exec-maven-plugin
.
I implemented it using it's official documentation here http://www.mojohaus.org/exec-maven-plugin/usage.html like this:
<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
Am I doing something wrong? I have already gone through post here Maven Run Project
Upvotes: 2
Views: 2591
Reputation: 329
Is your code compiled to target/classes/ ? If not your are maybe missing the maven compile phase? 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.
Try to do a mvn compile first before you exec.
Edit: See the correct answer here: How do I execute a program using Maven?
Upvotes: 1