mavenmaven-3exec-maven-plugin

Launching a windows batch script using Maven exec plugin blocks the build even though the script uses "start"


I am trying to perform integration tasting of the deployment of my application on the top of a custom container. Since my container is custom, I cannot use Maven Cargo plugin to setup the container.

My container:

My problem is that I have to run my container in a different process, because it needs to keep running while my tests are performed. Furthermorely, I have an API in my tests that let me wait for the container to be ready (a sort of lookup with timeout).

I have added the following lines to my pom.xml

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>scripts/start-agent.bat</executable>
            </configuration>
        </plugin>

This will call a script, which contains only

start call gs-agent.bat

However the mvn exec plugin gets stucked and my tests are not run. According to what is suggested in How do I run a batch file from my Java Application? , I have modified my pom.xml as the following:

 <configuration>
                <executable>cmd</executable>
                <arguments>
                    <argument>/C</argument>
                    <argument>start</argument>
                    <argument>gs-agent.bat</argument>
                </arguments>
            </configuration>

But this does not seem to solve the issue:

Maven halted


Solution

  • See this question: How do I run a batch file from my Java Application?

    Windows Batch Files are not executable. They are scripts that are run by the cmd executable.

    More Information

    Exec plugin source code reveals that Apache Commons Executor is used to actually execute the command line.

    There is a lot of reading you can do here, i.e. in the Apache Commons Executor documentation and their JIRA issues, but the short version is: this isn't a problem with "Maven," it's a problem with the platform-dependent nature of executing an exec() command.

    I've tackled this sort of problem before, and the solution I always devise is to deconstruct the .bat script into its actual commands and launch it directly from the exec plugin, rather than calling the script.