Category Archives: Windows

Remote debugging Tomcat7 servlets with Netbeans

At work we still use Tomcat 7 in production and I needed to set up debugging for various development systems. This article shows how to enable Tomcat 7 remote debugging

Enabling Tomcat 7 remote debugging via JDWP

Linux

I use Ubuntu 16.04 LTE so I’ll use that in the example, but other distros will not be that much different, except for the path and (re)starting the service of course.

  • Edit or create the file /usr/share/tomcat7/bin/setenv.sh and put in the following content:

    export JAVA_OPTS=”-Xdebug \
    -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n”

    Note: Obviously if the file already exists and it already has some content, then just add the parameters instead of adding the entire line.

  • Restart Tomcat

    sudo service tomcat7 restart

Windows

  • Go to the Tomcat binary directory, which is by default

    c:\Program Files\Apache Software Foundation\Tomcat 7.0\bin

  • Start the program Tomcat7w.exe
  • Switch to the java tab and add the following lines to the Java options textbox:

    -Xdebug
    -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

    Note: It is important that each of the parameters should be added on separate lines, and that lines should have no whitespaces in the end!

  • Restarts Tomcat 7

    net stop tomcat7
    net start tomcat7

Attaching Netbeans debugger to Tomcat 7

Now that we have Tomcat running with the remote debugging on we can attach Netbeans to debug.

  • Click debug – attach debugger, a dialog box will appear
  • Select Java Debugger (JPDA) as the Debugger
  • Select SocketAttach as Connector
  • Fill in host / IP address to the host field
  • Fill in port to the Port field, in this example the port is 8787, but obviously it can be any non-taken port
  • Click OK
  • If everything went OK the debugging tab should show up showing the running threads

…and that’s it! Happy bug hunting!

Advertisements