exec-maven-plugin产生的进程会阻止Maven进程 [英] Process spawned by exec-maven-plugin blocks the maven process
问题描述
我正在尝试使用maven执行以下方案:
I am trying to execute the following scenario using maven :
- 集成前阶段:使用主类(使用exec-maven-plugin)启动基于Java的应用程序
- integration-phase:运行集成测试用例(使用maven-failsafe-plugin)
- 集成后阶段:优雅地停止应用程序(使用exec-maven-plugin)
这是pom.xml片段:
Here is pom.xml snip:
<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集成后测试,则我的应用程序将作为maven进程的子进程启动,但是该应用程序进程阻止maven进程执行下一阶段的集成测试.后来我发现在maven exec插件中有一个错误(或缺少功能?),因为该应用程序进程阻塞了Maven进程.为了解决这个问题,我将MyApp.java的调用封装在外壳脚本中,然后附加了"/dev/null 2>& 1&"产生一个单独的后台进程.这是来自runTest.sh的片段(这只是一个片段,而不是实际的片段):
If I execute mvn post-integration-test, my application is getting started as a child process of the maven process, but the application process is blocking the maven process from executing the integration tests which comes in the next phase. Later I found that there is a bug (or missing functionality?) in maven exec plugin, because of which the application process blocks the maven process. To address this issue, I have encapsulated the invocation of MyApp.java in a shell script and then appended "/dev/null 2>&1 &" to spawn a separate background process. Here is the snip (this is just a snip and not the actual one) from runTest.sh:
java - DMY_APP_HOME =$2 com.foo.MyApp > /dev/null 2>&1 &
尽管这解决了我的问题,但是还有其他方法可以解决吗?我是否缺少exec-maven-plugin的任何论点?
Although this solves my issue, is there any other way to do it? Am I missing any argument for exec-maven-plugin?
推荐答案
您可以使用async配置参数来实现所需的功能.另请参阅asyncDestroyOnShutdown,它将默认在JVM退出时关闭应用程序.
You can use the async configuration parameter to achieve what you require. Also see asyncDestroyOnShutdown which will shutdown the app on JVM exit by default.
https://www.mojohaus.org/exec -maven-plugin/exec-mojo.html#async
如果将其设置为true,则子进程将异步执行,并且构建过程将继续并行执行.
If set to true the child process executes asynchronously and build execution continues in parallel.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</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>
<async>true</async>
</configuration>
</plugin>
这篇关于exec-maven-plugin产生的进程会阻止Maven进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!