Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven and Exec: forking a process?

Tags:

maven

exec

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>

and my batch file looks like this:

start myApplication.exe

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

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

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

like image 955
Dan Vinton Avatar asked Jan 12 '11 12:01

Dan Vinton


2 Answers

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>
like image 115
Dan Vinton Avatar answered Oct 31 '22 16:10

Dan Vinton


Try 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>call</executable>
                <arguments>
                    <argument>start_application.bat</argument>
                </arguments>
                <workingDirectory>./path/to/application</workingDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>
like image 1
javamonkey79 Avatar answered Oct 31 '22 16:10

javamonkey79