Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Develop Aspect-Oriented Java Applications with Eclipse and AJDT

By Matt Chapman, Dr. Helen Hawkins
2005-05-16


Debugging

Debugging applications containing aspects is as easy as debugging applications without them, so if you're used to using the Java debugger within Eclipse, there is again nothing really new for you here. Since the advent of AJDT 1.1.11, setting breakpoints in before and after advice is the same as setting breakpoints in methods. Setting breakpoints in around advice is slightly different; if you want the debugger to stop at such a breakpoint, you need to turn inlining off. To do this, go to Window>Preferences>AspectJ>Compiler and navigate to the Advanced tab. Once there, check the No inline option and click OK.

To show in more detail how similar debugging AspectJ applications is to debugging standard Java applications, let's set a breakpoint in the Spacewar example and step through the code. First, switch to the Debug perspective by going to Window>Open Perspective>Debug. Since we looked at the Display class in the Aspect Visualization perspective, let's put a breakpoint into the after () returning (Player player): call(Player+.new(..)) advice. Open Display.java class and navigate to the after returning advice, as shown in Figure 13. Then, either double-click in the gutter next to the line Enumeration elements = DISPLAYS.elements(); or right-click and select Toggle Breakpoint from the same place.

Figure 13. Setting a breakpoint
Setting a breakpoint

After setting the breakpoint, to launch the application in debug mode, follow the same steps as you would with a plain Java application. From the green bug's drop-down menu (the green bug is located on the workbench toolbar) select your Spacewar run configuration, and you're off! If you don't have a Spacewar run configuration set up, then from the same drop-down menu, select Debug... Create a new Java application configuration that runs the main() method in the spacewar.Game class, then press Debug.

As soon as the breakpoint is reached, the debug mode pauses the Spacewar application, as shown in Figure 14. Information about all the current variables can be found in the Variables view in the top right-hand corner of the Debug perspective, and the stack trace of the current thread can be found in the Debug view in the top left of the Debug perspective. The point in the code where you are paused can be seen in the Editor. To step through the code, just press the Step Over button in the Debug view. It's as easy as that!

Figure 14. Reaching a breakpoint
Reaching a breakpoint



Tutorial Pages:
» Updated tools make AOP easier for beginners and veterans alike
» Installing AJDT
» First steps
» The Outline view and editor markers
» The Spacewar example
» Build configurations
» Aspect Visualization perspective
» Debugging
» Generating documentation
» Further options
» Conclusion
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» All about JAXP, Part 1
» Make Database Queries Without the Database
» Load List Values for Improved Efficiency
» 2 Ways To Implement Session Tracking
» A Simple Way to Read an XML File in Java
» Java Validation With Dynamic Proxies