Welcome!

IBM Cloud Authors: Zakia Bouachraoui, Elizabeth White, Yeshim Deniz, Pat Romanski, Liz McMillan

Related Topics: IBM Cloud

IBM Cloud: Article

Remote Debugging

Remote Debugging

This article will introduce you to the powerful remote debugging features of WebSphere Studio Application Developer 5.0 and show you how to debug a J2EE application deployed in a remote application server.

I will walk you through the process of creating a simple Web application in WebSphere Studio, deploying it in a remote WebLogic server, and using the remote debugging features to debug Web application components such as a servlet and a JavaBean. I assume that you are already familiar with deploying a Web application on an application server, so I will not go into the details of Web application deployment.

Configuring the WebLogic Server for Remote Debugging
Sun introduced the Java Platform Debugging Architecture (JPDA) as a standard for debugging distributed Java applications. This standard allows tool and server vendors that support JPDA to seamlessly allow debugging on different host operating systems. In order to set up a WebLogic server for debugging, I added the following entry to the line in the WebLogic startup script that invokes the server:

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,
server=y,address=60000, suspend=n -Djava.compiler=NONE

The following is a brief explanation of the debug parameters:

  • -Xdebug: Enables debugging.
  • -Xnoagent: Sun's classic VM supports both the old sun.tools.debug interface and JPDA; the -Xdebug option enables both, but defaults to running the sun.tools.debug agent. The -Xnoagent option turns this off so the JPDA will work. The HotSpot VM does not have this option. If you are using the HotSpot VM, this entry is optional.
  • -Djava.compiler=NONE: Disables the JIT compiler. Debugging with the classic VM requires that its JIT compiler be disabled. For the HotSpot VM, this entry is optional.
  • -Xrunjdwp: Loads in-process debugging libraries and specifies the kind of connection to be made. The transport=dt_socket option tells the debugger which transport mechanism to use. Specifying the dt_socket option allows the debugger to listen to a socket for incoming client connections. The other possible value is dt_shmem, which is applicable when both the debugger and the application server are on the same host. The server=y option indicates that the JVM is running in debug mode. The address= 60000 entry indicates that the server listens to incoming connections in port 60000. This has to be a free port in the system. The suspend=n option instructs the server not to wait until a debugger connection is established. If the suspend=y option is used, then the application server will suspend at the beginning of execution and wait until the debugger attaches to it.

    Consult your application server documentation for details on the debugging parameters.

    Figure 1 shows the output of my WebLogic 6.1 Server startup script, hosted on a Sun SPARC machine and listening to HTTP port 60000.

    Creating a New Web Project
    I updated my WebSphere Studio installation with the WebSphere Studio Application Developer fix pack PTF 001 (www3.software.ibm.com/ibmdl/pub/software/ websphere/studiotools/html/ptf001/wssd50/install.html), which contains a number of bug fixes. In order to create a new Web project, launch WebSphere Studio and do the following:
    1.  Click on "File", select "New", and "Web Project". Create a project named Testproject. Make sure you have J2EE 1.3 as the selected J2EE level. Create a new project under your workspace.
    2.  Add a new servlet, select the J2EE perspective on the left side of the IDE, right-click on Java Source under the Testproject, and select "New" followed by "Servlet". Follow the prompts to create a servlet named TestDebugServlet in "mypackage". The source code for TestDebugServlet is shown in Listing 1.
    3.  Add a new JavaBean, select the J2EE perspective, right-click on Java Source under the Testproject, and select "New" followed by "Class". Follow the prompts to create a JavaBean named TestDebugBean in a package "mypackage". The source code for TestDebugBean is shown in Listing 2.
    4.  Add a new JSP page, select the J2EE perspective, right-click on "Web Content" under the Testproject, and select "New" followed by "JSP". Follow the prompts to create a JSP page named Testpage.jsp. The source code for Testpage.jsp is shown in Listing 3.
    5.  Modify the web.xml under the WEB-INF folder, as shown in Listing 4. I have /TestDebugServlet as the URL pattern for TestDebugServlet.

    Once you have completed creating the Web application, you will have a view similar to that shown in Figure 2.

    Deploy the Web Application
    The project files, namely the JSP file, the web.xml file, and the class files, will be located under the project workspace. I used the context name "Testproject" for the Web application. It is very handy to have a simple FTP script to automate the job of transferring the files to the appropriate location in the remote application server installation. If you are using Ant to build your application, you may use the FTP Ant task to automate file transfer. Refer to http://ant.apache.org/manual/OptionalTasks/ftp.html for details. During development, you may choose to use either a WAR file deployment or an exploded Web application directory structure. Once the Web application is compiled and built, the process of transferring the files to the remote server should be no more than a mouse-click away.

    Create a Server Configuration for Remote Debugging
    Follow the steps below for creating a new server configuration for the remote WebLogic Server.
    1.  On the top menu bar, click on "Window", "Show view", and select "Server Configuration". You may have to select the "Server Configuration" option from the "Other.." menu item, depending on whether or not you have made a previous selection.
    2.  On the server configuration pane, right-click on "Servers", click on "New", "Server and Server Configuration". You will be prompted with a dialog box, as shown in Figure 3.
    3.  Select "Remote application server attach" from the list and enter a server name, for example, "WebLogic test server". You will be prompted to enter the hostname, JVM debug port, and HTTP port. For the Testproject, my values are 6000 for the HTTP port and 60000 for the debug port.

    Now you have configured a server that can be used for remote debugging.

    Start Remote Debugging
    Debugging the application is as simple as connecting the server you have configured to your application server and typing in the URL of the Web application on a browser. Follow the following steps to attach the WebSphere debugger to the remote application server:
    1.  On the top menu bar, click on "Window", "Show view", and select "Server". You may have to select the "Server" option from the "Other.." menu item, depending on whether or not you have made a previous selection.
    2.  Right-click on the "WebLogic test server" that you created earlier, and click on debug. If your application server is configured properly, your debugger will connect to it. A "Servers" pane similar to that shown in Figure 4 will appear.

    Now you can switch to the Debug perspective, the one with the bug symbol on the left side. You can set breakpoints on the servlet or on the JavaBean by double-clicking on the left side of the source code pane. Once you launch the browser to point to the TestDebugServlet on your application server, WebSphere Studio will intercept your calls and you can break at the location that you desire.

    Note: You may have to select "Window", "Show view", and "Debug" again to view the Debug pane. Now you can see the various debug options, as shown in Figure 5. You can also watch variable values by selecting the variable of interest in the code window and viewing the value on a tool tip.

    Conclusion
    WebSphere Studio 5.0 comes with powerful debugging features that allow you to debug applications on local machines as well as remote application server hosts. Once the code, build, deploy, and debug cycle has been set up properly for a project, debugging an application on a different JVM on a different host operating system should be a smooth task.

  • More Stories By Sankar Venkitachalam

    Sankar Venkitachalam is a senior developer at Bank One, where he focuses on designing, implementing, and supporting Bank One Card Services J2EE and content management projects. He has worked in J2EE-related technologies for the past three years and is certified in J2EE. Sankar holds a master's degree in computer science from Cleveland State University.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    IoT & Smart Cities Stories
    Moroccanoil®, the global leader in oil-infused beauty, is thrilled to announce the NEW Moroccanoil Color Depositing Masks, a collection of dual-benefit hair masks that deposit pure pigments while providing the treatment benefits of a deep conditioning mask. The collection consists of seven curated shades for commitment-free, beautifully-colored hair that looks and feels healthy.
    The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
    The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
    We all love the many benefits of natural plant oils, used as a deap treatment before shampooing, at home or at the beach, but is there an all-in-one solution for everyday intensive nutrition and modern styling?I am passionate about the benefits of natural extracts with tried-and-tested results, which I have used to develop my own brand (lemon for its acid ph, wheat germ for its fortifying action…). I wanted a product which combined caring and styling effects, and which could be used after shampo...
    The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected pat...
    There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
    Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
    At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
    Druva is the global leader in Cloud Data Protection and Management, delivering the industry's first data management-as-a-service solution that aggregates data from endpoints, servers and cloud applications and leverages the public cloud to offer a single pane of glass to enable data protection, governance and intelligence-dramatically increasing the availability and visibility of business critical information, while reducing the risk, cost and complexity of managing and protecting it. Druva's...
    BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.