exec-maven-plugin 生成的进程会阻止 maven 进程

2024-03-18

我正在尝试使用 maven 执行以下场景:

  1. pre-integration-phase :使用主类启动基于 java 的应用程序(使用 exec-maven-plugin)
  2. Integration-phase :运行集成测试用例(使用 maven-failsafe-plugin)
  3. 集成后阶段:优雅地停止应用程序(使用 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 进程执行下一阶段的集成测试。后来我发现有一个错误(或缺少功能?) http://jira.codehaus.org/browse/MEXEC-87在maven exec插件中,由于应用程序进程阻塞了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 的任何参数?


您可以使用 async 配置参数来实现您的需求。另请参阅 asyncDestroyOnShutdown ,默认情况下,它将在 JVM 退出时关闭应用程序。

https://www.mojohaus.org/exec-maven-plugin/exec-mojo.html#async https://www.mojohaus.org/exec-maven-plugin/exec-mojo.html#async

如果设置为 true,则子进程异步执行,并且构建执行继续并行。

    <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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

exec-maven-plugin 生成的进程会阻止 maven 进程 的相关文章

随机推荐