![](/img/trans.png)
[英]The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java are missing or invalid
[英]Run main from test scope in Maven: “The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java are missing or invalid”
我想执行一个位于测试src文件夹中的主类。 我试过了:
mvn -q exec:java \
-Dexec.mainClass=com.example.beanoverriding.EmbeddedApplication \
-Dexec.classpathScope="test"
但得到:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project bean-overriding:
The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java are missing or invalid -> [Help 1]
查看实际代码:
编辑:像这样写它:
mvn -q exec:exec \
-Dexec.executable=java \
-Dexec.args="-cp %classpath com.example.beanoverriding.EmbeddedApplication" \
-Dexec.classpathScope="test"
使用classpathScope = test(参见http://www.mojohaus.org/exec-maven-plugin/java-mojo.html#classpathScope)
根据文档,您确实应该设置exec.mainClass属性。 但这似乎并不是主要类别。
使用-X
选项执行命令时( mvn -X exec:java -Dexec.mainClass=com.example.beanoverriding.EmbeddedApplication -Dexec.classpathScope=test
)Maven会显示有关配置的更多信息:
<configuration>
...
<classpathScope default-value="runtime">${exec.classpathScope}</classpathScope>
...
<mainClass>${start-class}</mainClass>
...
</configuration>
似乎主类是由start-class
属性设置的......所以似乎在某些配置中覆盖了属性。 确实如此。 它在spring-boot-starter-parent
pom中。 请参阅https://github.com/spring-projects/spring-boot/blob/v2.1.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/pom.xml
因此,使用当前配置,以下命令将完成此任务:
mvn -X exec:java -Dstart-class=com.example.beanoverriding.EmbeddedApplication -Dexec.classpathScope=test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.