Thursday 14 February 2008

Jetty with Maven

One of the things that Maven always promised to deliver was a dramatic reduction of development time and more uniform development patterns. The jetty plugin from mortbay really does deliver on these promises - it is one of those plugins that really make me sit back and go "why didn't anyone do this sooner".

Basically, for when your developing a webapp and need a quick test of it, then jetty comes to the rescue. Simply drop the following configuration into your webapp's pom.xml:

<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
Then from the command line run:
  mvn jetty:run
This will start up jetty and run from the target/${build.finalName} directory - this means that as you continue developing Jetty is updated with the changes you make as you rebuild your artifact.



Pretty cool! This plugin obviously comes with a whole bunch of configuration options, but in it's default state it suits most of my needs. The only configuration I usually use is to update the port that Jetty is hosted on, this following config does that for you, updating the port to :8081

<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8081</port>
</connector>
</connectors>
</configuration>
</plugin>
More details on the plugin can be found at http://www.mortbay.org/maven-plugin
which covers more configuration options you can shake a stick at!

I've been using this whilst developing Apache Tuscany enabled webapps, it really has improved my turnaround, so I thought it'd be useful to share!

No comments: