Remote debugging is sometimes useful to identify bugs that are not easily reproducible in the local environment.
On the server in the .bash_profile of the tomcat user I put the following.
export JAVA_HOME="/usr/local/jdk1.6.0" export CATALINA_HOME=/usr/local/tomcat export JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" export JPDA_ADDRESS=8000 export JPDA_TRANSPORT=dt_socket
Shut down and start up again tomcat to activate the debugging port 8000.
$ bin/shutdown.sh && tail -f logs/catalina.out $ bin/startup.sh && tail -f logs/catalina.out
Check that port 8000 is indeed activated:
$ telnet localhost 8000 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Connection closed by foreign host.
Now we need to set up a ssh tunnel to be able to connect remotely through the firewall. For example with Putty load your previously saved connection, go to Connection:SSH:Tunnels insert 8000 in source port, localhost:8000 in destination and tick “Local ports accept connections from other hosts” if you need to use the tunnel from other hosts of your local network, like in my case I’ve to use it from vmware. Finally click add, then open. This tunnel will not be saved, if you need to save it go to the Session tab and press save. After connecting, it’s possible to connect to port 8000 of the machine with putty and tunnel the connection to the remote host.

Now on the Netbeans side, open the same project, with source in sync and choose attach debugger (the blue arrow right of run and debug or from the menu Run:Attach Debugger.

Change the host according to your needs, normally it will be localhost because it would be the same host running Putty, otherwise specify the IP address.
Finally we’re ready to set breakpoints and debug as usual.