Remote Debugging Server Side Java


Introduction:-
 

More application developers and IT organizations are developing applications based on a distributed model. A distributed application in Java will often need to work on many different deployment platforms. In order to deliver robust distributed applications, developers must be able to debug code running on disparate platforms.

Debugging server side Java presents many challenges for developers. A typical scenario would is debugging Java code running in Presentations Servers, Application Servers and Database Servers. The figure below shows the standard Internet platform and Application Programming Model described by Sun Microsystems.

Traditional debugging of remote programs often involves wrapping the server side code into a temporary local program and running the program in a local environment using the local debugging capabilities of an Integrated Development Environment. Other approaches involve manually adding numerous System.out.println() statements in the code path, running the program on the server side and retrieving the printed statements from log files. For instance you can have several System.out.println() statements in a Java Servlet or JSP page running in Apache JServ. The output can be viewed in the jserv.log file.

Another option would be to run Java Servlets and JavaServer Pages (JSP) in a temporary local server in the IDE. Most of the IDEs provide little or no support for debugging Enterprise Java Beans (EJB).

The traditional way of debugging server side Java code is both cumbersome and inefficient. It adds significant overhead for developers who need to write code snippets to make server side code run in local environments. Local debugging may also mask or introduce bugs that appear when server side Java is running in a real server.

Implementation and solution:-
 

Java Platform Debugger Architecture (JPDA) provides new debugging support for the Java 2 Platform. JPDA delivers the infrastructure necessary for tools vendors to build powerful debuggers which run across multiple platforms, virtual machine (VM) implementations and SDK versions. The figure below shows the architecture.

Oracle JDeveloper 3.1 offers support for remotely debugging server side Java using JPDA. This allows developers to debug Java code running in different remote servers. JDeveloper's remote debugging support includes breakpoints, conditional breakpoints, watch expressions and the ability to step through code one statement or one procedure at a time and display the values of variables and properties. With JDeveloper 3.1, the same intuitive GUI debugger can now be used for both local and remote debugging.

Remotely Debugging Oracle8i

Oracle JDeveloper allows you to remotely debug Enterprise Java Beans, Corba Server Objects and Java Stored Procedures running in Oracle8i Release 2 (8.1.6). The figure below shows remote debugging of EJB running in Oracle8i.

Oracle JDeveloper 3.1 also includes a debug on demand feature which allows developers to remotely debug Java Stored Procedures, EJB and Corba Server Objects when being called from external programs such as SQL*Plus, Java Servlets etc..

Remotely Debugging BEA WebLogic ServerTM

Similarly, Oracle JDeveloper allows developers to remotely debug Enterprise JavaBeans (EJB), Java Servlets and JSP pages running in BEA Weblogic Server. The figure below shows remote debugging an EJB running in Weblogic Server. The EJB has been invoked from a DOS client in step 1. The execution of the EJB gets halted at the specified breakpoint in step 2.

Remotely Debugging Apache JServ

Similarly, Oracle JDeveloper allows developers to remotely debug Java Servlets and JSP pages running in Apache JServ. The figure below shows remote debugging of a Java Servlet running in Apache JServ. Step 1 shows the Java Servlet being called from the browser and step 2 shows the execution of Servlet code being stopped at the specified breakpoint.


 

Example: Remote Debugging Java Servlets in Apache JServ
 

The following section gives a detailed example of remote debugging Java Servlets in Apache JServ with JDeveloper 3.1
  • Start JServ using the following debug parameters. 
    • In jserv.properties set wrapper.bin.parameters= -ojvm -XXdebugondemandquietport4000 to use the Oracle JVM. The 'ondemand' parameter will start the Java program right away, allowing a debugger to connect at any time. Otherwise the Java program stays halted until a debugger is connected. The 'port4000' parameter indicates that the debugger must connect at the specified port. (The default port is 4000). The 'quiet' parameter suppresses connection messages which otherwise get printed to the 'standard error' output.
    • In jserv.properties set wrapper.bin.parameters=-classic -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4000 -Xdebug -Xnoagent -Djava.compiler=NONE to use the classic VM . To learn more about the invocation options for JPDA, see the Sun VM Invocation Options.
    • In jserv.properties set wrapper.bin=\java1.2\bin\java.exe and wrapper.path=\jpda-1.0\bin
    • Add servlet.jar (found in the JDeveloper installation) to the classpath of JServ.
  • Start Oracle JDeveloper and open the below servlet project in the JDeveloper IDE.
The figure shows JDeveloper with a project named REMOTEDEBUGSERVLET.jpr. Selecting the mainServlet.java shows the method signatures and import statements.
  • Change the project properties for the Servlet project. In the Run/Debug tab set the "Debug File as" option to 'Remote Debugging'. Uncheck 'Compile project before running or debugging'.

     
  • Set a breakpoint in the Servlet code.

     
  • Start the debugger by selecting the Run|Debug menu option. This will bring up the Remote Debugging dialog. Choose Oracle JVM option if you are using the Oracle JVM or Java Platform Debugging Architecture for classic VM. Specify the hostname where JServ is running. The port number has to be identical to the one specified in the JServ properties file. Clicking on Attach will start the debugger in JDeveloper.

     
  • In this example we have specified the VM to debug on demand. When we start the Java Servlet from the browser using the correct URL, the Servlet will stop at the breakpoint specified. From this point onwards you can debug the Servlet as if you were debugging it locally. You can look at the value of variables and expressions or jump to conditional breakpoints or the next breakpoint.

Summary:-
 

Server side debugging or distributed debugging is a key feature for application developers building multi-tier applications. Oracle JDeveloper's remote debugging capabilities provide significant productivity gains for application developers. They can test and debug distributed code from their development environment without the overhead of adding numerous arcane println() statements to their code. Oracle JDeveloper allows developers to Develop and Debug server side Java from a productive and intuitive IDE.

 


Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065, USA
http://www.oracle.com
Worldwide Inquiries:
1-800-ORACLE1
Fax 650.506.7200
Oracle, JDeveloper, and Enabling the Information Age are trademarks of Oracle Corporation.
All other company and product names mentioned are used for identification purposes only, and may be trademarks of their respective owners
Copyright Oracle Corporation 1999
All Rights Reserved
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy