Maven – Start Jetty Server by Ant task using maven-antrun-plugin

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:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.