Setup Jetty/Maven for developing web applications in Eclipse

This article describes how to set up the development environment in Eclipse to run/debug web applications for Maven based projects.

Install

First you would need to add Eclipse plugin to run Maven tasks. I use the Maven Integration [2]. Follow the instruction in the web site on how to install the plugin in Eclipse.

Second, add jetty plugin to your project’s pom.xml file. For example

<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopPort>9966</stopPort>
<stopKey>foo</stopKey>

</configuration>
</plugin>

More configuration options can be found in the plugin documentation [2].

Config and Run

Now you are ready to configure Eclipse to run/debug your web application on Jetty.

Open Eclipse’s Run Configuration and create a new configuration under Maven Build and enter jetty:run in Goal field. Running the configuration will start a Jetty instance on localhost:8080.

To debug jetty, open Eclipse’s Run Configuration and create another new configuration under Maven Build. Set the Goal value to jetty:run as before.  Then enter the following in the VM arguments field under the JRE tab:

-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y

Now create a new Debug Configuration under Remove Java Application. Make sure the port number is identical to the value set above (i.e. 4000).

To run Jetty in debug mode, first start the jetty:run run configuration. The following will be displayed in the Eclipse Console:

Listening for transport dt_socket at address: 4000

Now start the debug configuration and Jetty should be started.

To stop jetty, create and run a Run Configuration under Maven Build with Goal jetty:stop.

More Info

  1. Jetty - http://jetty.codehaus.org/jetty/
  2. Maven Integration m2e plugins – http://www.eclipse.org/m2e/
  3. Jetty Maven plugin – http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin
About these ads

About Raymond Lee
Professional Java/EE Developer, software development technology enthusiast.

Comments are closed.