Maven & Java: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java are missing or invalid

梦想的初衷 提交于 2019-11-28 08:58:42
bronson

"configuration" must go outside "executions", like this:

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
            <execution>
                <goals>
                    <goal>java</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <mainClass>com.emilio.App</mainClass>
        </configuration>
    </plugin>
</plugins>

Make sure you execute the mvn exec:java from within the same directory where your pom.xml with exec configuration resides.

Configuration seems correct with missing id parameter inside execution part. Proper way would be:

<executions>
    <execution>
        <id>someID</id>
        <goals>
            <goal>java</goal>
        </goals>
        <configuration>
            <mainClass>org.aptovia.javaee7.CDBOOKSTORE.Main</mainClass>
        </configuration>
    </execution>
</executions>

Assuming you are running main method using maven, execution would be like below:

mvn exec:java@someID

someID added inside execution part.

If the <configuration> is outside the <executions> , it is the configuration for the plugin to be used no matter what the life-cycle phase is.

If the <configuration> is inside the <executions>, it is the configuration to be used in certain life-cycle phase.

As Vabis has suggested, use mvn exec:java@someID to execute the specific execution of the goal for a plugin.

For more information, please see https://maven.apache.org/guides/mini/guide-configuring-plugins.html.

There is no such parameter like mainClass in exec-maven-plugin, try to use:

<configuration>
   <executable>java</executable>
   <arguments>
     <argument>-classpath</argument>
     <classpath/>
     <argument>org.aptovia.javaee7.CDBOOKSTORE.Main</argument>
   </arguments>
</configuration>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!