Maven和Java:目标组织的参数'mainClass',codehaus,mojo:exec-maven-plugin:1.2.1:java丢失或无效

w41d8nur  于 2023-01-01  发布在  Java
关注(0)|答案(6)|浏览(138)

我的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]

但是在我的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>

根据以下内容,看起来也正常:https://www.mojohaus.org/exec-maven-plugin/usage.html
我已经做了一个mvn清理,重建,但仍然得到这个错误。真的不知道发生了什么:(
任何帮助非常感谢!

disho6za

disho6za1#

“配置”必须在“执行”之外,如下所示:

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

fquxozlt2#

确保在pom.xml with exec配置所在的同一目录中执行mvn exec:java

p8ekf7hl

p8ekf7hl3#

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

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

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

移动虚拟机执行代码:java@某个ID

在执行部分内添加了someID。

lrpiutwd

lrpiutwd4#

如果<configuration><executions>之外,则无论处于哪个生命周期阶段,它都是要使用的插件的配置。
如果<configuration>位于<executions>内部,则该配置将用于特定生命周期阶段。
正如Vabis所建议的,使用mvn exec:java@someID来执行插件目标的特定执行。
有关详细信息,请参阅https://maven.apache.org/guides/mini/guide-configuring-plugins.html

juud5qan

juud5qan5#

如果你有参数要传递给主类,那么下面的结构会有所帮助。

<build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>org.rraj.server.EchoServer</mainClass>
          <arguments>
            <argument>8585</argument>
          </arguments>
        </configuration>
      </plugin>
    </plugins>
  </build>

如果你觉得这个答案有帮助,请投赞成票:)

beq87vna

beq87vna6#

exec-maven-plugin中没有类似mainClass的参数,请尝试用途:

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

相关问题