Debugging Java code in Eclipse

When doing debugging of Java code it is very useful to be able to set breakpoints in order to figure out what is going on with your code. By setting breakpoints while testing your Web application the debug time can be significantly reduced.

To enable breakpoints and debugging in Eclipse for DHIS 2 Web development, first set up a debugger:

  1. Right-click any project in Eclipse, e.g. dhis-web-dataentry, and go to "Debug As" > "Debug Configurations".
  2. Right-click "Remote Java Application" and click "New". Leave settings under Connect as it is.
  3. Click "Source" tab, then "Add", then "Java project", then "Select All" and "OK".
  4. Click "Apply".

To start debugging a web project from the command line:

  1. In the terminal navigate to a web project directory and execute "mvnDebug jetty:run" to start the Maven Jetty plugin. It will output "Listening for transport dt_socket".
  2. Go back to Eclipse, find the debugger and click "Debug". You can see the Jetty plugin continue to start up in the terminal.
  3. You can now define your break-points anywhere in the code. Watch the breakpoints kick in while you use the web application.

Back to tutorials