我已经启动了一个新的maven项目并配置了 exec-maven-plugin
设置默认值 mainClass
,我可以使用
mvn exec:java -q
Hello World!
但是,如果我尝试在命令行上指定不同的main类,这似乎会被忽略:
mvn exec:java -Dexec.mainClass="com.jamesmcguigan.kdt.App2" -q
Hello World!
如果我注解掉 exec-maven-plugin
节,但最好在 pom.xml
为了 maven exec:java
并且有一种方法可以在 mvn exec:java -Dexec.mainClass="com.jamesmcguigan.kdt.App2"
.
还是我在这里遗漏了什么?
文件
pom.xml文件
<build>
<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.jamesmcguigan.kdt.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
src/main/java/com/jamesmcguigan/kdt/app.java
package com.jamesmcguigan.kdt;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
src/main/java/com/jamesmcguigan/kdt/app2.java
package com.jamesmcguigan.kdt;
public class App2
{
public static void main( String[] args )
{
System.out.println( "Hello World 2!" );
}
}
1条答案
按热度按时间xytpbqjk1#
使用属性,即:
然后:
mvn exec:java -Dmain.class="com.jamesmcguigan.kdt.App2" -q