Monday, June 27, 2011

Setting up debugging on Eclipse for web application on Jetty.

This is my first attempt to play around with Jetty when I came across a web application which this server came coupled with. In a desperate attempt to start the OAuth Web application (tutorial) which utilizes spring security, I came across few interesting aspects of Jetty and Maven which I am noting below so this post serves as my cheat sheet for later purposes! This post mainly concentrates on setting up a debugger on Eclipse for an application which runs on Jetty.

As my development box is Ubuntu (as of today its on Release 10.10 Maverick), I did install jetty and its required dependencies (either use a sudo apt-get install jetty or use a synaptic package manager). Once installed, since the web application was a maven project, I had to install that piece as well (sudo apt-get install maven2).

From the above tutorial, I got the copy of both the projects (svn co sparklr and tonr) and started sparklr project by doing inside the directory and running the command mvn jetty:run. I was more interested in understanding consumer part of OAuth and hence thought it would be a good idea to debug tonr project.

I spend one hour trying to set debugger in Intellij IDEA using this instructions but I was stuck as my IDEA didn't detect the Jetty version. After doing some searching over google, I gave up on setting debugger on IDEA and moved to eclipse. To my surprise, I found it lot easier to set it up.

Again being a maven project, I ran the command mvn eclipse:eclipse inside the tonr project dir. This command sets up the project wrt Eclipse and resolve the library dependencies.

Setting Debugger on Eclipse:
1) Open the tonr project in Eclipse. Click on Run->External Tools->External Tools Configurations....
2) Double Click on Program, now on the right hand side Main tab enter the location of mvn (in ubuntu its at /usr/bin/mvn) and set the working directory to project on hard disk, set Arguments with value "jetty:run".
3) Now click Environment tab, and click new button.
Put the name as MAVEN_OPTS with a value of -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4444,server=y,suspend=n. Now click apply and close the window.
4) Now setup the debug configuration by clicking: Run -> Debug Configurations. In the type-ahead select Remote Java Application. Enter the project name on the RHS (tonr in this case), host being localhost and port number 4444 (note this number should match the address in step 3). Now save the debug configuration.
5) Lastly, run the External tools by click on run button created at step 3. Once Jetty is started, click on Debug button by going to debug configuration created at step 4.

Above instructions from link.

This sets up the debugging.

1 comment:

  1. Have not used Jetty yet Amrut, but encountered it too this afternoon when installing and testing a different app.

    The guide makes me want to try the steps you have taken in setting them up w/ Eclipse.

    Yeah, a good way to keep notes of what you have been trying for future reference as well. Especially if steps are complete.

    ReplyDelete