Monday, March 26, 2012

Remote debugging maven jetty with IntelliJ Idea in Ubuntu 11.10

Jetty web server is an open source http server/client container which can be used to run and test webapps.  Jetty server provides a plugin to integrate with apache maven and it can be used to run a webapp in a maven project. To do this we need to add jetty-maven-plugin into our <plugins> section by adding it into webapp pom.xml file.

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.10</version>
            <configuration>
               <webXml>${project.build.directory}/jetty/WEB-INF/web.xml</webXml>
               <webAppConfig>
                  <contextPath>/${webapp.name}</contextPath>
                  <!--enable reloading static resources -->
                  <overrideDescriptor>src/test/resources/override-web.xml</overrideDescriptor>
               </webAppConfig>
               <scanIntervalSeconds>10</scanIntervalSeconds>
            </configuration>
         </plugin>


Now add the following Maven Options line into your .bashrc file.

For JDK 1.3 or above :
export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000"

For below JDK 1.3:
export MAVEN_OPTS="-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000"

Goto the webapp folder from terminal and enter,
 mvn jetty:run
Jetty server will start on debug mode and will listen on port 8000 now. The following info will be appeared in terminal.




Goto IntelliJ Idea project and create a remote debug confiruation giving following parameters. (to do this follow the path Run --> Edit Configurations. Click on the + button followed by Remote and you will see remote configuration window appears)


Host = localhost
Port = 8000

Run the remote debug and it will also listen on port 8000 now.

3 comments: