Posted by gsporar
on February 27, 2006 at 9:04 PM PST
Part 3 of this series shows how easy it is to use the debugger in the NetBeans IDE.
Part 1 of this series showed how to create a project for the uPortal
Quickstart source code. The project template used was "Web Application with Existing Ant Script."
This provides a significant advantage: by having the NetBeans
IDE use the Quickstart's build.xml you are guaranteed that the code
is built the same way both within and outside of the IDE.
There is a slight inconvenience, however, to creating what the NetBeans IDE refers to
as a "free-form" project. The inconvenience is that the build.xml from the Quickstart
does not contain targets that the IDE needs in order to perform "IDE only" functions.
Keep in mind that the NetBeans IDE uses Ant as the basis for its project
system. Every time you direct the IDE to do something with a project (clean, build,
deploy, run, etc.) what ends up happening is that the IDE runs an Ant target.
Since the build.xml from the Quickstart has no reason to include, for example, a target that
starts the NetBeans IDE's debugger then you will have to create one.
If the IDE had created the build.xml file then that
target (and several others) would be included.
Fortunately, creating the debugger target is easy because the IDE will do it for
you. The steps are:
1. Create .war and .jar Files
- Right-click the build.xml file and choose Run Target
> Deploy. This will create the .war and .jar files,
which the debugger will need later.
- Right-click the uPortal entry in the Projects window and
- Click the Output entry in the Category column on the left.
- Click the Add Jar/Folder button and then select the
uPortal.jar and uPortal.war files that are in the dist folder.
2. Start Tomcat in Debug Mode
In the Runtime window, expand the Servers entry and then
right-click the entry for Tomcat. If Tomcat is already running, choose
Stop. Right-click the entry for Tomcat and choose
Start in Debug Mode
3. Configure the Debugger Properties
- Verify that uPortal is the IDE's Main Project. Right-click
the uPortal entry in the Projects window and choose
Set Main Project.
- From the main menu, choose Run > Debug
Main Project. The IDE will display this dialog:
- Click the Generate button.
- The IDE will open the debug.properties file. By default
it directs the IDE's debugger to use a socket to communicate
with Tomcat. By default Tomcat is configured to use
shared memory when running on Windows. So if you are running
on Windows comment out the socket settings and un-comment
the shared memory settings so that it looks like:
- Change the client.url property to be
- Save the debug.properties file.
4. Start the Debugger
Once again, choose Run > Debug Main Project.
The uPortal logon page should be displayed in a browser.
5. Start Debugging
Set some breakpoints, watch the code run, in other words
all the usual stuff. There is helpful information on the
in the online guide to using the NetBeans IDE
. For example, setting a breakpoint on
line 227 of CSnoop.java and then logging into uPortal as
demo/demo resulted in the breakpoint being hit (click for full size):
When finished, select Run > Finish Debugger
Session. Also, note that for web applications like
uPortal, the HTTP Monitor is an additional debug tool provided by the NetBeans
IDE. For more information on it, refer
to the IDE's Help file.