当我从 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/