Maven 和 Java:目标 org.codehaus.mojo:exec-maven-plugin:1.2.1:java 的参数“mainClass”丢失或无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19850956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 20:41:48  来源:igfitidea点击:

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

javamavenexec-maven-plugin

提问by gvanto

My Java EE proj builds fine, but when trying to execute get following error:

我的 Java EE 项目构建良好,但在尝试执行时出现以下错误:

gert@gert-VirtualBox:~/workspace/CDBOOKSTORE$ mvn exec:java 
[INFO] Scanning for projects... 
[INFO]                                       
[INFO] ------------------------------------------------------------------------
[INFO] Building CDBOOKSTORE 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO]  
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ CDBOOKSTORE >>>    
[INFO]  
[INFO] --- maven-dependency-plugin:2.8:copy (default) @ CDBOOKSTORE ---
[INFO]  
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ CDBOOKSTORE <<<    
[INFO] 
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ CDBOOKSTORE ---
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2.505s [INFO] Finished at: Fri Nov 08 14:01:40 EST 2013 
[INFO] Final Memory: 9M/21M 
[INFO] ------------------------------------------------------------------------    
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project CDBOOKSTORE: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java are missing or invalid
-> [Help 1]

But in my pom.xmlfile (which I've edited following a Java EE book example), I havespecified the mainClassconfig:

但在我的pom.xml文件(我已经编辑下面一个Java EE书例子),我已经指定的mainClass配置:

 <?xml version="1.0" encoding="UTF-8"?> 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>

     <groupId>org.aptovia.javaee7</groupId>
     <artifactId>CDBOOKSTORE</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <packaging>app-client</packaging>

     <name>CDBOOKSTORE</name>

     <properties>
         <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>

     <dependencies>
         <dependency>
             <groupId>javax</groupId>
             <artifactId>javaee-api</artifactId>
             <version>7.0</version>
             <scope>provided</scope>
         </dependency>

         <dependency>
            <groupId>org.jboss.weld.se</groupId>
            <artifactId>weld-se</artifactId>
            <version>2.1.0.Final</version>
         </dependency>

     </dependencies>

     <build>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.1</version>
                 <configuration>
                     <source>1.7</source>
                     <target>1.7</target>
                     <compilerArguments>
                         <endorseddirs>${endorsed.dir}</endorseddirs>
                     </compilerArguments>
                 </configuration>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-acr-plugin</artifactId>
                 <version>1.0</version>
                 <extensions>true</extensions>
                 <configuration>
                     <archive>
                         <manifest>                            
                             <mainClass>org.aptovia.javaee7.CDBOOKSTORE.Main</mainClass>
                         </manifest>
                     </archive>
                 </configuration>
             </plugin>

             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-dependency-plugin</artifactId>
                 <version>2.8</version>
                 <executions>
                     <execution>
                         <phase>validate</phase>
                         <goals>
                             <goal>copy</goal>
                         </goals>
                         <configuration>
                             <outputDirectory>${endorsed.dir}</outputDirectory>
                             <silent>true</silent>
                             <artifactItems>
                                 <artifactItem>
                                     <groupId>javax</groupId>
                                     <artifactId>javaee-endorsed-api</artifactId>
                                     <version>7.0</version>
                                     <type>jar</type>
                                 </artifactItem>
                             </artifactItems>
                         </configuration>
                     </execution>
                 </executions>
             </plugin>

              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>                         
                            <mainClass>org.aptovia.javaee7.CDBOOKSTORE.Main</mainClass>
                        </configuration>
                    </execution>
                </executions>
             </plugin>

         </plugins>
     </build>

 </project>

Also looks OK according to this: https://www.mojohaus.org/exec-maven-plugin/usage.html

根据这个看起来也不错:https: //www.mojohaus.org/exec-maven-plugin/usage.html

I've done an mvn clean, rebuilt, but still getting this error. Really not sure whats happening :(

我已经完成了 mvn clean,重建,但仍然收到此错误。真的不知道发生了什么:(

Any help much appreciated!

非常感谢任何帮助!

回答by ragnor

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

没有像mainClassexec-maven-plugin这样的参数,尝试使用:

<configuration>
   <executable>java</executable>
   <arguments>
     <argument>-classpath</argument>
     <classpath/>
     <argument>org.aptovia.javaee7.CDBOOKSTORE.Main</argument>
   </arguments>
</configuration>

回答by 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>

回答by Vaibs

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

执行部分中缺少 id 参数的配置似乎是正确的。正确的方法是:

<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:

假设您正在使用 maven 运行 main 方法,执行将如下所示:

mvn exec:java@someID

mvn exec:java@someID

someID added inside execution part.

在执行部分添加了 someID。

回答by George

Make sure you execute the mvn exec:javafrom within the same directory where your pom.xmlwith exec configuration resides.

确保mvn exec:javapom.xmlwith exec 配置所在的同一目录中执行。

回答by CatSleeping

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.

如果在<configuration>之外<executions>,则无论生命周期阶段是什么,它都是要使用的插件的配置。

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

如果<configuration>位于 内部<executions>,则它是要在某个生命周期阶段使用的配置。

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

正如 Vabis 所建议的,用于mvn exec:java@someID执行插件目标的特定执行。

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

有关更多信息,请参阅https://maven.apache.org/guides/mini/guide-configuring-plugins.html