Saturday, November 17, 2007

Debugging a web application with IntelliJ IDEA, Maven and the jetty plugin

Hi,

Today I was doing some development in the most recent build of IntelliJ IDEA (found here), and toying with it I have found a quick way to debug any web application which is built using Maven.
It is a must in my developments to use the jetty maven plugin, so I can just start the application using:

mvn jetty:run

And then edit my pages and stuff without having to restart, or deploy to external web containers. To do that you just need to declare the jetty plugin in your POM file:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>maven-jetty-plugin</artifactId>
  <version>6.1.2</version>
  <configuration>
    <connectors>
    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
        <port>8080</port>
      </connector>
    </connectors>
    <scanIntervalSeconds>10</scanIntervalSeconds>
  </configuration>
</plugin>

Open you project with IntelliJ IDEA (it is nice that now you can just open a maven POM as a project!), and then you can use this plugin to start the web application and start debugging right away. To do so:

  1. Create a new Run/Debug configuration (click on the drop down list on the left of the green arrow icon) and "Edit configurations".
  2. Click on the '+' (plus) button and create a new "Maven" configuration.
  3. Give it a name.
  4. In the goals section just put "jetty:run"
  5. And you are good to go!

Set some breakpoints and you can debug the web application now just clicking on the "debug" button.

Enjoy!

5 Comments:

Blogger KesheR said...

My job-mates will appreciate me for this, thank you very much!

11:31 AM  
Anonymous Perdita said...

Keep up the good work.

11:59 AM  
Anonymous Golf Lessons said...

Apparently the mvn jetty plugin doesn't work if your pom already has a dependency on jetty.
I was curious if anybody else has a mechanism for stoping and starging a jetty instance from mvn? Thanks!

12:23 PM  
Blogger Jude said...

This worked for me right off the bat. The only other thing I had to do was select the working directory (the directory containing the POM). Not complicated.

This saved me a chunk of time so thanks for posting.

Btw, this works with IDEA IntelliJ 10.5 Community Edition, Maven 3, and Jetty 6. A 2007 solution that still works in 2011. Very good.

1:03 PM  
Blogger Steve Smith said...

Great and Useful Article.

JSF Online Training

JSF Training

JSF Interview Questions

JSF Tutorials

7:53 AM  

Post a Comment

<< Home