Configuring Eclipse for Remote Debuggingby Deepak Vohra08/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. 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:
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
Developing a JBoss Application in EclipseAfter 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
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:
The example servlet is mapped to the URL pattern /catalog. The structure of the web application is illustrated below.
Building and Deploying with AntThe compiling, packaging, and deploying of the web application is done in the Eclipse IDE with an Ant build.xml file. Develop an Ant build.xml file that consists of targets to compile the JBossServlet.java file and package and deploy the webapp.war web application. The build.xml file is listed below:
The build.xml file has the properties listed in the following table.
build.xml also has the following targets:
The Back to EclipseCreate a new project in the Eclipse IDE. Select File -> New -> Project, as shown in Figure 1.
This displays the New Project frame. In the New Project wizard, select Java -> Java Project. Click the Next button: this brings up the New Java Project frame. In the New Java Project frame, specify a project name--
In the Java Settings frame, add a source folder to the project with the Add Folder button, as illustrated in Figure 3.
This brings up the New Source Folder frame. Use this to specify a folder name; src, for example. This adds a source folder to the project. A message prompt gets displayed, asking you to update the source folder and the output folder. In the New Java Project frame, click the Finish button to create the project, as shown in Figure 4.
A new project gets added to the Eclipse IDE, as shown in Figure 5.
Next, select File -> Import to import the example servlet source folder to the project. The project‘s src folder and build.xml file need to be imported if the src folder and build.xml file were not created in the Eclipse IDE. In the Import Select frame, select File System and click the Next button. In the Import File System frame, select the src folder and the build.xml file, and click the Finish button, as shown in Figure 6.
This adds the servlet source files to the project, as shown in Figure 7.
Run the build.xml file to compile, package, and deploy the servlet web application to the JBoss server. Right-click the build.xml file and select Run -> Ant Build, as shown in Figure 8.
Ant generates the web application .war file webapp.war and deploys it to the JBoss application server‘s deploy directory. The output from Ant is shown in Figure 9.
Next, start the JBoss server with the bin/run script. Invoke the example servlet in a web browser with the URL http://localhost:8080/webapp/catalog. The
Configuring a Remote Debugging Configuration in EclipseTo remotely debug a JBoss application in Eclipse, start the JBoss server in debug mode. Set the JBoss server to debug mode by setting the debug options in the bin/run batch script file. The debugging provided by JBoss is based on the Java Platform Debugger Architecture (JPDA). Set the
The different debug parameters are:
For further explanation of the debug settings, refer to the JPDA documentation. To demonstrate the remote debugging feature of Eclipse, we need to throw an exception in
with
Next, configure a debug configuration for the Eclipse project. Select the Debug option in the Debug Option List, as shown in Figure 11.
This displays the Debug frame. In the Debug frame, select the Remote Java Application node. Right-click the node and select New, as shown in Figure 12.
In the Debug Configuration frame, specify a name for the debug configuration. Select the project that is to be debugged, namely the
Next, add exception breakpoints to the JBossServlet.java file. Earlier, we added a
In the Add Java Exception Breakpoint frame, select the
If a Remote Debugging a JBoss ApplicationHaving configured a debug configuration for the example servlet application deployed in the JBoss server, we shall debug the servlet application in the Eclipse IDE. Create a webapp.war web application from the modified (with the Next, select the EclipseDebug debug configuration in the Debug frame. Click on the Debug button to connect the remote debugger to the JBoss server, as shown in Figure 16.
This connects the Eclipse remote debugger to the JBoss server. Select the Debug Perspective button to display Eclipse‘s debug perspective. In the Debug perspective, the remote debugger is shown connected to the JBoss server at localhost, port 8787, as shown in Figure 17.
Access the
The line that throws the exception is ConclusionWe remotely debugged an application deployed to the JBoss server in the Eclipse IDE. An application deployed in another application server such as WebLogic may also be debugged by configuring that server to start in debug mode. ResourcesDeepak Vohra is a NuBean consultant and a web developer. Copyright ?2005 O‘Reilly Media, Inc. |
|