I have the following shell script to start the Jetty Server in my portable web application in Windows.
start_jetty.bat
start java -DSTOP.PORT=8080 -DSTOP.KEY=stop_jetty -jar start.jar EXIT
It will prompt a new cmd window for the Jetty console. So i want to run this shell script during the pre-integration-test life cycle of the Maven project such that a testable webapp instance is started up before the integration test begins. Therefore, i make use of the maven-antrun-plugin in the pom and run this shell script by the <exec> Ant task. Unfortunately, the Maven build console hangs after the jetty server is started as it tries to wait for the shell script to be completed.
Finally, the problem is solved after adding the spawn attributes in the <exec> task which makes the Ant task run in background. The following is a sample of the maven-antrun-plugin configuration.
... <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>pre-integration-test</id> <phase>pre-integration-test</phase> <configuration> <tasks> <!-- Start 8081 jetty --> <exec dir="<jetty_path>" executable="cmd.exe" spawn="true"> <arg value="/c"/> <arg value="start_jetty.bat"/> </exec> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> ...
Done =)
Reference:
- Re: maven-antrun-plugin exec task. Windows. Can’t leave process running in the background.
- Ant – Exec Task
Filed under: Jetty, Maven Tagged: Ant, Jetty, Maven, maven-antrun-plugin, Shell Script