Maven和Exec:分配流程?

时间:2011-01-12 12:34:11

标签: maven exec

我正在尝试使用Maven在运行某些集成测试之前启动它。我在Windows上。 My 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 个答案:

答案 0 :(得分:12)

对于记录,一个相当狡猾的解决方案是使用maven-antrun-plugin来调用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 :(得分: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>