Configuring Eclipse for Remote Debugging

by Deepak Vohra
08/31/2005

If a J2EE developer has deployed an application in an application server and wants to debug the application from the Eclipse IDE, the Eclipse IDE provides a remote debugger to connect to the application server and debug the application. Without a debugger, the error message has to be obtained from the application server's error logs.

Related Reading

Eclipse IDE Pocket Guide
By Ed Burnette

With the remote debugger provided by Eclipse, breakpoints may be added to the application file, allowing you to debug the application in Eclipse. When an application is run in an application server like JBoss and the application generates an error, the application gets suspended and the Eclipse IDE Debug perspective displays the line that has generated the error. In this tutorial, we shall debug a JBoss application server application in Eclipse.

To debug, we will do the following:

  1. Start the JBoss server.
  2. Connect the Eclipse remote debugger to the JBoss server.
  3. Debug in the Eclipse GUI.

We shall develop an example servlet application and deploy the application in JBoss. First, the servlet is run without any error; subsequently, an error is introduced into the servlet to demonstrate the remote debugging feature in Eclipse.

Preliminary Setup

  1. Download the jboss-4.0.2.zip file.
  2. Install the JBoss 4.02 application server by extracting the .zip file to an installation directory.
  3. Download the Eclipse 3.0 or Eclipse 3.02 .zip file eclipse-SDK-3.0-win32.zip.
  4. Install the Eclipse 3/3.02 IDE.

Developing a JBoss Application in Eclipse

After installing the JBoss server and the Eclipse IDE, develop a servlet application to run and debug in the JBoss server. The example servlet application consists of a doGet method that prints out a String message to the browser. The example servlet, JBossServlet.java, is listed below:

package servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class JBossServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Eclipse Remote Debugging");
  }
}

Create a directory structure for a web application. Create a WEB-INF directory and a classes directory in the WEB-INF directory. Create a package directory, servlets, for the example servlet, and copy the JBossServlet.java file to the servlets directory. Create a web.xml deployment descriptor for the web application. Copy the web.xml file to the WEB-INF directory. The web.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<web-app
xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <display-name>JBossServlet</display-name> <servlet-name>JBossServlet</servlet-name> <servlet-class>servlets.JBossServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>JBossServlet</servlet-name> <url-pattern>/catalog</url-pattern> </servlet-mapping> </web-app>

The example servlet is mapped to the URL pattern /catalog. The structure of the web application is illustrated below.


     /WEB-INF
      |      |
   web.xml classes
                 |
                 servlets
                      |
                     JBossServlet.class

Pages: 1, 2, 3, 4, 5, 6, 7, 8

Next Pagearrow