paul
paul

Reputation: 4487

exec-maven-plugin is giving class not found exception

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:

  1. mvn exec:java java.lang.ClassNotFoundException: com.demo.printTest.HelloWorld
  2. mvn exec:exec java
  3. mvn java

Am I doing something wrong? I have already gone through post here Maven Run Project

Upvotes: 2

Views: 2591

Answers (1)

Stefan H&#246;ltker
Stefan H&#246;ltker

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

Related Questions