【发布时间】:2012-04-13 19:25:58
【问题描述】:
我正在尝试使用 maven 执行以下场景:
- 预集成阶段:使用主类(使用 exec-maven-plugin)启动基于 java 的应用程序
- 集成阶段:运行集成测试用例(使用 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 (or missing functionality?),就是因为这个应用进程阻塞了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 的任何参数?
【问题讨论】:
标签: maven integration-testing maven-plugin exec-maven-plugin