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

exec plugin is not able to do this, and I found the issue for it, too: http://jira.codehaus.org/browse/MEXEC-87

In the jira issue linked above, there is a mention and a link of a fork for exec plugin that would have the functionality.

Other than that, I think you'll need to use an antrun-plugin for the time being.

Here's an example taken from working configuration and run with mvn verify. This needs to be in the <plugins>, not <pluginManagement> (exec could reside in pluginmanagement just fine).

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <phase>pre-integration-test</phase>
            <configuration>
                <target>
                    <exec executable="cmd.exe"
                          spawn="true">
                        <arg value="/c"/>
                        <arg value="D:\myfolder\test.bat"/>
                    </exec>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
       </execution>
   </executions>      
</plugin>

Note that spawn="true" is key here if you don't want the execution to block, like specified in the question. If you do want it to block and see the output immediately, set it to false.


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.