How do i debug a web application running on jetty in eclipse?

43,731

Solution 1

Click External Tools Config,

enter image description here

Select program and click the new button top left. Set location to your maven binary working directory to local workspace and arguments to jetty:run enter image description here

In the environment tab set the maven opts. Notice socket address = 4000 and suspend=y enter image description here

The go to debug configurations and add a new remote application. Add a project name and set the socket address. Now run the External tool it should say:

Listening for transport dt_socket at address: 4000

Then you can debug the remote app and add breakpoints etc.

enter image description here enter image description here

Solution 2

I would run the application with maven using the command: mvnDebug jetty:run

And setup a remote Java application using port 8000, in Eclipse IDE.

See the 'Setting up Maven 2.0.8+' section of: http://docs.codehaus.org/display/MAVENUSER/Dealing+with+Eclipse-based+IDE

Solution 3

None of the answers worked for me. Here's what did work:

  • Create Maven Eclipse Runtime for your project:
  • right-click on project -> maven build -> goals: jetty:run
  • go to JRE tab of your Maven Eclipse Runtime, and in the VM arguments section add:

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

When you execute this runtime, the first thing the Eclipse console outputs (in blue) is:

Listening for transport dt_socket at address: 8000

Now you can create a Remote Java application Debug Runtime and connect to the debug port (8000 in this example)

Solution 4

I would just expand eaykin's answer as the URL is broken.

Run the Mvn Debug as bellow...

$ mvnDebug -Dmaven.test.skip -Denvironment=dev clean jetty:run

This will wait on port 8000

Preparing to Execute Maven in Debug Mode Listening for transport dt_socket at address: 8000

Then go to the Eclipse Run --> Debug Configurations --> Remote Java Applications Define Host as 'localhost' and port as 8000 if they are not default.

If you click on the "Debug" button, this will start the application from mvn.

Share:
43,731
ollo
Author by

ollo

Updated on July 05, 2022

Comments

  • ollo
    ollo almost 2 years

    never done web programming before. Is there a way to set breakpoints, see variable values in eclipse? The app i want to debug makes a Query string whcih i would like to easily extract.

  • ollo
    ollo over 12 years
    trying to run it this way i get CreateProcess error=193, %1 is not a valid Win32 application. And trying to debug it using this setup i get connection refused. What are the prerequisites for this to work? the project uses ant command to run jetty. isnt there a way to run it like that from commandline and attach the debugger inside the IDE?
  • Usman Ismail
    Usman Ismail over 12 years
    The /usr/bin/mvn is a *nix path change that to c:\where_maven_is_installed. or if you want to run through command line just set the MAVEN_OPTS as a system variable and run mvn jetty:run on command line
  • ollo
    ollo over 12 years
    I discovered something called run-jetty-run, trying to configure that atm. I hope it is a valid option for debugging. I will try again with maven if this fails. thanks for your help, great post btw.
  • Usman Ismail
    Usman Ismail over 12 years
    Post an answer or comment when you get run-jetty-run working. vote for the answer if it helps and accept one of the answers.
  • ollo
    ollo over 12 years
    The project build is way too complicated for me to understand and get a debugger working, so i gave up for the time being. I will vote up your answer since it might be helpful for others
  • chrisjleu
    chrisjleu about 10 years
    For information: I needed to set the JAVA_HOME variable correctly in addition to MAVEN_OPTS for it to work.