Debugging Java code

 

 

In this Topic...

Configure the Server for Debug

Configure the Designer for Debug

Run in Debug Mode

Related Topics...

Overview: Debugging an Application

How do I... Debug an Application

How do I... Log Application Behavior

We can step through Java code generated for the model, or through any Java code made accessible to the model by LJO Builder Calls.

By default, the Portlet Factory stores generated Java code in the following directory:

WEB-INF/factory/generated/genjava/

The Java source files you will use for debugging are located in this directory.

There are three steps to debugging Java code:

  • Step 1 - Configure the Server for Debug

  • Step 2 - Configure the Designer for Debug

  • Step 3 - Run the Model in Debug mode

Here are the procedures required to complete each step.

 

Configure the Server for Debug

The process you use to configure the server for debug depends on the server you are running. The procedures described below provide an example procedure based on the WebSphere Portal Server.

  1. To configure the WebSphere Portal 5.x server for debug, use the Portal server Admin tool to access the Portal Server s "Configuration" page. Find this page at: Servers | Application Servers | WebSphere Portal.

  2. On the Configuration page locate the link titled, "Debugging Service." This link provides access to the Portal Server s "Debug General Properties" page.

  3. On the Debug General Properties page turn server debugging on by enabling the "Startup" check box.

Note that on this page we can also set various debug parameters for the Portal server, including the JVM Debug Port to which Designer can connect to receive debug information. Make a note the port number that will be used for debug output.

Once you have the server configured for debug operation, we can debug Factory code running on the server by configuring the Designer as indicated in Step 2 below.

Note: If you use Apache Tomcat for development, click here to view information about setting up that server up for debug operations.

 

Configure the Designer for Debug

Follow these steps to configure the Designer for debugging

  1. If you have not done so already, add the WEB-INF/factory/generated folder as a Source directory for your project.

Do this in the Project Properties | Java Build Path dialog. This directory contains the generated Java source files for each model.

Note: If the Java source files for your LJO builder calls do not reside in the WEB-INF/work/source directory, add the directory in which they do reside as a Source folder for the project.

  1. If you have not done so already, we need to establish a Debug configuration. Click Run | Debug to open the Debug Configuration dialog.

  2. In the tree-list of debug configurations, choose "Remote Java Application" and click New.

  3. Provide a name for this debug configuration. For example, "Factory-Java Debug".

The right pane of the Debug Configuration dialog displays a set of inputs allowing you to set the host name and port on which the application server is running.

  1. Set port number to the same value as the port number you set when you enabled debugging on the portal server. The default WebSphere debugging port is 7777.

  2. Set the host name to that of the machine on which the server is running.

  3. In the Source tab of the Debug configuration, add the path to your project's WEB-INF/factory/generated directory in the application server as a Directory.

If the directory doesn't show up, make sure you have opened the model you want to debug -- you may have to regen the model to force generation of the Java code. If needed, move the entry you just added below the Default folder.

  1. Click OK to save this Debug Configuration.

 

 

Run Model in Debug mode

Follow these steps to initiate debugging of Java code:

 

Add a Breakpoint to the Code

  1. Open the Java source file for an LJO or the generated Java source file for the model.

For example, for a model named, "Test" in the WEB-INF/models directory, you would find its generated Java source file in:

WEB-INF/factory/generated/genjava/_Test.java

  1. Set a breakpoint at the desired spot in the code.

 

Run the Model to Initiate Debugging

  1. In the Designer, choose Run >Debug >Factory Debug (or whatever name you provided during the debug configuration dialog)

Wait until the debugger is finished loading.

  1. Run the model.

When the debugger hits the first break point, the Debugging perspective will display, and the code at your breakpoint will be highlighted.

  1. Debug the code for your model as you would any other Java application.