Search code examples
mavenclassnotfoundexceptionclassnotfoundmaven-failsafe-pluginexec-maven-plugin

Maven exec plugin Class Not Found Exception


when I right click on the class that has the main() method in Eclipse, and go into properties -> resource, the path to the class is this:

/UserRegistrationServices/src/main/java/main/Application.java

In my POM.xml file I have this:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>my-execution</id>
                        <phase>package</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>UserRegistrationServices.src.main.java.main.Application.java</mainClass>
                </configuration>
            </plugin>

But for some reason maven cannot find the class.

Help would be appreciated, thanks.


Solution

  • The <mainClass> element takes a fully qualified class name. The fully qualified name of a class consists of the package and the actual name of class. In a default Maven project, the package name is relative to src/main/java. That means, the package of your Application class is main. You can verify that by looking at the package declaration in the class itself.

    Therefore the <mainClass> value needs to be main.Application.