我正在尝试使用 maven 执行以下场景:
- pre-integration-phase :使用主类启动基于 java 的应用程序(使用 exec-maven-plugin)
- integration-phase :运行集成测试用例(使用 maven-failsafe-plugin)
- post-integration-phase:优雅地停止应用程序(使用 exec-maven-plugin)
这是 pom.xml 片段:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>launch-myApp</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-DMY_APP_HOME=/usr/home/target/local</argument>
<argument>-Djava.library.path=/usr/home/other/lib</argument>
<argument>-classpath</argument>
<classpath/>
<argument>com.foo.MyApp</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<forkMode>always</forkMode>
</configuration>
</plugin>
</plugins>
如果我执行 mvn post-integration-test,我的应用程序将作为 maven 进程的子进程启动,但应用程序进程阻止 maven 进程执行下一阶段的集成测试。后来我发现maven exec插件中有一个bug(或者缺少功能?),因为应用程序进程阻塞了maven进程。为了解决这个问题,我将 MyApp.java 的调用封装在一个 shell 脚本中,然后附加“/dev/null 2>&1 &”以生成一个单独的后台进程。这是来自 runTest.sh 的片段(这只是一个片段,而不是实际的片段):
java - DMY_APP_HOME =$2 com.foo.MyApp > /dev/null 2>&1 &
虽然这解决了我的问题,但还有其他方法吗?我错过了 exec-maven-plugin 的任何论点吗?