Maven和Exec:分叉一个过程? [英] Maven and Exec: forking a process?

查看:87
本文介绍了Maven和Exec:分叉一个过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Maven启动应用程序,然后再对其进行一些集成测试.我在Windows上.我的Maven插件配置如下:

I'm trying to use Maven to start an application prior to running some integration tests on it. I'm on Windows. My Maven plugin configuration looks like this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <id>start-my-application</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>start_application.bat</executable>
                <workingDirectory>./path/to/application</workingDirectory>
            </configuration>
        </execution>
    <executions>
<plugin>

我的批处理文件如下:

start myApplication.exe

单独运行时,批处理文件会生成一个单独的窗口来运行应用程序并立即返回控制权.

When run in isolation, the batch file spawns a separate window to run the application and immediately returns control.

然而,当从Maven运行时,该构建会等待单独窗口中的过程完成后再继续.这在某种程度上违反了集成测试阶段的要点...

However, when run from Maven, the build waits for the process in the separate window to finish before continuing. This somewhat defeats the point of the integration testing phase...

有什么想法可以在Maven中启动一个真正独立的过程以允许构建继续进行吗?

Any ideas how I can start a truly separate process in Maven to allow the build to continue alongside it?

推荐答案

记录上,一个比较棘手的解决方案是使用maven-antrun-plugin调用Ant,该Ant能够生成单独的进程:

For the record, a rather hackish solution is to use maven-antrun-plugin to call Ant, which is capable of spawning separate processes:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <phase>pre-integration-test</phase>
            <configuration>
                <target>
                    <exec executable="cmd"
                          dir="./path/to/application"
                          spawn="true">
                        <arg value="/c"/>
                        <arg value="start_application.bat"/>
                    </exec>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
       </execution>
   </executions>
</plugin>

这篇关于Maven和Exec:分叉一个过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆