Debugging applications
To debug an application we use a development environment like the IBM Rational Application Developer for WebSphere to create a Java project. We then import the program to debug into the project.
Two debugging modes are available:
- Step-by-step
Prompts you whenever the server calls a method on a web object. A dialog lets you step into the method or skip it. In the dialog, we can turn off step-by-step mode when we are finished using it.
- Breakpoints
Debug specific parts of programs. Add breakpoints to the part of the code that we must debug and run the program until one of the breakpoints is encountered.
Breakpoints actually work with both styles of debugging. Step-by-step mode just lets you see which web objects are being called without having to set up breakpoints ahead of time.
We do not need to import an entire program into your project. However, if we do not import all of our program into the project, some of the source might not compile. We can still debug the project. Most features of the debugger work, including breakpoints, stepping, and viewing and modifying variables. We must import any source that to set breakpoints in.
The inspect and display features in the source view do not work if the source has build errors. These features let us select an expression in the source view and evaluate it.
Import app into a Java project then debug
- Open New Project dialog and select...
Java | Java Project | Next
- Specify a name for the project, for example, WASExamples, then click Finish..
- Select the new project, then open the import file system dialog...
File | Import | File System | Next
- Browse the directory for files.
Go to the following directory:
profile_root/installedApps/node/DefaultApplication.ear/DefaultWebApplication.war
- Select DefaultWebApplication.war from the Import dialog and then click Finish.
This imports the JavaServer Pages files and Java source for the examples into your project.
- Add any JAR files needed to build to the Java Build Path.
Properties (right-click) | Java Build Path node | Libraries | Add External JARs
- Add...
profile_root/installedApps/node/DefaultApplication.ear/Increment.jar
...then select it and use the Attach Source function to attach the Increment.jar file because it contains both the source and class files.
Other Jar files to add...
- app_server_root/dev/JavaEE/j2ee.jar
- app_server_root/plugins/com.ibm.ws.runtime.jar
- app_server_root/plugins/com.ibm.ws.webcontainer.jar
Click OK when we have added all of the JARs.
- We can set some breakpoints in the source at this time if you like, however, it is not necessary as step-by-step mode will prompt you whenever the server calls a method on a web object. Step-by-step mode is explained in more detail later in this topic.
- To start debugging, we need to start the WAS in debug mode and make note of the JVM debug port. The default value of the JVM debug port is 7777.
- When the server is started, switch to the debug perspective by selecting...
Window | Open Perspective | Debug
We can also enable the debug launch in the Java Perspective by choosing...
Window | Customize Perspective | Other | [Debug | Launch]
- Select the workbench toolbar Debug pushbutton and then select WAS Debug from the list of launch configurations. Click the New pushbutton to create a new configuration.
- Give the configuration a name and select the project to debug (the new WASExamples project).
Change the port number if we did not start the server on the default port (7777).
- Click Debug to start debugging.
- Load one of the examples in your browser. For example: http://your.server.name:9080/hitcount
What to do next
To learn more about debugging, launch The IBM Rational Application Developer for WebSphere, select Help > Help Contents and choose the Debugger Guide bookshelf entry. To learn about known limitations and problems associated with the IBM Rational Application Developer for WebSphere, see the IBM Rational Application Developer for WebSphere release notes. For current information available from IBM Support on known problems and their resolution, see the IBM Support page.IBM Support has documents that can save you time gathering information needed to resolve this problem. Before opening a PMR, see the Must gather documents page for information to gather to send to IBM Support.
Subtopics
- Debugging components in the IBM Rational Application Developer for WebSphere
- Attaching a Rational tool to a remote debug session
The following steps describe how to attach an IBM Rational Application Developer for WebSphere Software product to a remote debug session on WAS for z/OS .- Unit testing with DB2
These steps describe how to setup a unit test environment that would allow us to develop and unit test code with DB2 z/OS to support Container Managed Persistence (CMP) development and access DB2 test data that resides on z/OS.- Debugging Service details
View and modify the settings used by the Debugging Service.