Maven和Exec:分叉进程?

14

我正在尝试使用Maven在运行一些集成测试之前启动一个应用程序。 我在Windows上。我的Maven插件配置如下:

<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

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

但是,当从Maven中运行时,构建将等待在单独窗口中运行的进程完成后才继续。这有点违背了集成测试阶段的目的...

有任何想法可以在Maven中启动一个真正的独立进程,以允许构建与之同时进行吗?

2个回答

12

记录一下,一个相当hack的解决方案是使用maven-antrun-plugin来调用Ant,Ant能够生成独立的进程:

<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>

1

试试这个:

<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>call</executable>
                <arguments>
                    <argument>start_application.bat</argument>
                </arguments>
                <workingDirectory>./path/to/application</workingDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

很抱歉,没有运气——一个单独的 cmd shell 窗口出现了,但是创建它的原始 mvn 调用被阻塞并等待它... - Dan Vinton
嗯,奇怪。在我的测试中,这似乎是有效的。好吧 - 很抱歉它对你没用。 - javamonkey79
此外,这只适用于Windows操作系统。(对于OP来说没问题,但可能不适用于其他人。) - Barett

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接