[英]Maven run class before test phase: exec-maven-plugin exec:java not executing class
[英]How to run a main class from test sources with exec maven plugin?
我有以下用于 exec maven 插件的 pom.xml 配置,但它仅在主 class 在 src/main/java 中时有效,如果它在 src/test/java 中则无效。 我不希望这个主要的 class 最终出现在分发/发布中。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>myexec</id>
<phase>generate-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<classpathScope>test</classpathScope>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.mypackage.SomeMainClass</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
这里的问题是我试图在编译之前运行 class(在生成测试源步骤之后,它与测试源一起编译)。 com.mypackage.SomeMainClass
生成测试源 *TestCase.java 编译运行。
那么,如果我不希望主要的 class 最终出现在已发布的 jar 中,我该怎么办? 我宁愿不为此开发 maven 插件。
最简洁的解决方案可能是将此 class 视为其自己的外部可执行文件,从而将其构建为单独的模块。 这将涉及将该项目变成一个 Maven 多模块项目(如果它还不是的话)。
https://www.mojohaus.org/exec-maven-plugin/examples/example-exec-using-plugin-dependencies.html
然而,快速而肮脏的解决方案...... Maven 允许您设置排除项。 如果您不希望某些内容出现在版本 jar 中,请将其过滤掉。 IE :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.