java - 使用命令行执行java程序时maven报错

标签 java bash maven maven-2

当我从 Netbeans 运行 Maven 项目时,一切正常。但是,当我使用命令行时:

mvn exec:java -Dexec.mainClass="Main.Laucher" -Dexec.args=$args1 $args2 $args3

我收到此错误:

     [ERROR] BUILD FAILURE
     [INFO] ------------------------------------------------------------------------
     [INFO] Invalid task '1': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or
 pluginGroupId:pluginArtifactId:pluginVersion:goal
     [INFO] ------------------------------------------------------------------------
     [INFO] For more information, run Maven with the -e switch
     [INFO] ------------------------------------------------------------------------
     [INFO] Total time: < 1 second
    [INFO] Finished at: Mon Apr 21 12:06:23 CEST 2014
     [INFO] Final Memory: 7M/491M

maven 版本是:

Apache Maven 2.2.1 (rdebian-8)
Java version: 1.7.0_51
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux" version: "3.2.0-58-generic" arch: "amd64" Family: "unix"

pom.xml中我有exec-maven-plugin:

     <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>simulation.amazon.Laucher</mainClass>
    </configuration>
    </plugin>

如何解决此错误?

最佳答案

您需要配置exec-maven-plugin插件您的pom.xml例如:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            ...
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>com.example.Main</mainClass>
          <arguments>
            <argument>argument1</argument>
            ...
          </arguments>
          <systemProperties>
            <systemProperty>
              <key>myproperty</key>
              <value>myvalue</value>
            </systemProperty>
            ...
          </systemProperties>
        </configuration>
      </plugin>
    </plugins>
  </build>
   ...
</project>

关于java - 使用命令行执行java程序时maven报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23195228/

相关文章:

c - 获取脚本中exe的返回值

用于构建多模块maven项目的windows脚本

maven - 运行 maven 命令时如何禁用控制台消息?

eclipse - 当我执行项目 -> clean 时,TestNG 测试用例未编译

java - 正则表达式完全匹配字符串

java - 在 java 中获取 URL 参数并从该 URL 中提取特定文本

java - Openshift 访问 context.xml

bash coproc 和剩余的 coproc 输出

linux - 如何定位最大的目录

java - 从 java 调用 python 方法