Remote Debugging with NetBeans IDE 4.1 and its Bundled Servers
By Geertjan-Oracle on Apr 13, 2005
Create and deploy a web application. (For purposes of this procedure, I created the web application described in the NetBeans IDE 4.1 Quick Start Guide for Web Applications. I then deployed the application to both bundled servers.)
In the IDE, go to the Runtime window (Ctrl-5), expand the Servers node, right-click the node for the server, and click Start/Stop Server.
Click Start Server (Debug). This starts the server in debug mode.
- In the Output window at the bottom of the screen, you'll see something like this (you'll see the first when starting the Tomcat Web Server in debug mode, and the second for the Sun Java System Application Server in debug mode):
Listening for transport dt_shmem at address: tomcat_shared_memory_id
Listening for transport dt_shmem at address: localhost4848
(To change to a socket connection with a port number, stop the server in the Runtime window, right-click it, choose Properties, and change the Debug settings at the bottom of the Properties dialog box.)
Select Run > Attach Debugger from the main menu.
Choose SharedMemoryAttach in the Connector field and type tomcat_shared_memory_id or localhost4848 in the Name field. (If you're using a socket connection with a port number, choose SocketAttach instead.) You'll see something like this (you'll see the first when attaching to the Tomcat Web Server in debug mode, and the second for attaching to the Sun Java System Application Server in debug mode):
Attaching to tomcat_shared_memory_id User program running
Attaching to localhost4848 User program running
Set breakpoints. For example, set them in namehandler.java, if you're using the document mentioned in step 1 above.
In your browser, do something to access the file containing the breakpoints. For example, go to the following URL, if you're using the document mentioned in step 1 above (use the first for the Tomcat Web Server, and the second for the Sun Java System Application Server, assuming you're using the default port numbers):
In the IDE, you can now step through your code. When using the Sun Java System Application Server, you'll see the following interesting dialog box displayed in the IDE:
Now that I've got this working, I'll start working out how it all works (and if it works) for JBoss, Tomcat 4, and JRun4. Especially in the latter case, I think, there'll be problems (browsing the Internet, I found a few people claiming that debugging isn't supported by JRun4).
Update 04/20/05: Yes, it really works for JBoss, Tomcat 4, and JRun4. And it's pretty similar to how it works for the bundled servers. For details, click here.