Debugging WebLogic Server Applications Using Eclipse and the WebLogic-Plugin
by Jeremy Whitlock
02/28/2006
Sample Application
For brevity, the application we will debug is a Hello World EJB. The source for this example has been zipped up and can be accessed here. There is a little bit of setup required in order to build the deployable JAR. The following sections describe the setup procedures. Note that we assume that you have already imported the zipped up project into Eclipse.
Create the WEBLOGIC Eclipse User Library
- Window > Preferences > Java > Build Path > User Libraries.
- Click the New... button and give the User library name a value of WEBLOGIC.
- With the WEBLOGIC User Library selected, click the Add JARs... button.
- Browse to your
WEBLOGIC_HOME/server/lib
directory and add theweblogic.jar
and thewebservices.jar
. - Close all dialogs to have Eclipse rebuild your application with the new User Library.
The reason you have to create the WEBLOGIC User Library is because our EJB requires the WebLogic JARs in the WEBLOGIC User Library to compile. It is much easier to create User Libraries because you can use them over and over in other projects.
Source modifications
- Modify the
PROJECT_HOME/src/com/jwhitlock/HelloWorldClient.java
to have proper values for URL, username and password on lines 19, 20 and 21, respectively. - Modify the
PROJECT_HOME/build.xml
to have the proper value for your WebLogic home on line 5.
Assuming everything is configured properly, you should be able to run Ant on the
PROJECT_HOME/build.xml
and have it run successfully. You can do this by opening the build.xml in Eclipse and doing the following in the
Outline view:
Right-Click "distribute[default]" > Run As > 2 Ant Build
If you get any build errors, look at the Console view for errors so you can resolve and try again.
Deploying Applications
Well...we now can start WebLogic Server. We can build the application too but to have some real fun, and to see how the WebLogic-Plugin really shines, let's get to the deployment and debugging of our application.
To deploy an application to your running WebLogic Server via the WebLogic-Plugin, all you have to do is right-click the server and fill the dialog out accordingly. The basics of this dialog describe the type of deployment, whether it's archived or exploded, and the path to the deployment. That is it. Let's see this in action:
- Start the WebLogic instance as mentioned earlier.
- Build the application by running Ant on the
PROJECT_HOME/build.xml
. - Right-click the WebLogic instance and choose the Deploy menu item.
- Select the
Archived radio button and browse to
PROJECT_HOME/dist/helloworld.jar
.
Now watch the magic. Upon successful deployment, you'll get the usual debug information from the console. You also get real-time updates to your deployments tree in the WebLogic Servers view. As soon as WebLogic acknowledges that your application deployed successfully, the WebLogic Servers view will notify you of everything that was deployed. This becomes very useful when deploying whole applications with more than just a single EJB.
Figure 3 shows how the Weblogic Servers view updates when the EJB is successfully deployed.
Figure 3. WebLogic Servers view updating after successful EJB deployment
Debugging The Application
Now that we've taken care of the basics on how to use the plug-in, we are ready to debug. Here are the requirements:
- To debug a deployed application, that application must be in an Eclipse project in your workspace.
- You must add the project that holds your application to your server's classpath using the Edit WebLogic Server Instance dialog. (This may not be required before the 1.0 final release.)
- The server must be configured to run in Debug Mode.
Since we are using the bundled Eclipse application mentioned earlier, Number 1 is not a problem. Number 2 is the first problem we run into because earlier, we just created values for the General tab. Let's fix this first before going on to the next:
- While the configured WebLogic Server is stopped, double-click the server in the WebLogic Servers view to open the Edit WebLogic Server Instance dialog.
- Click the Classpath tab.
- Select the Post-startup WebLogic Classpath and the Pre-startup WebLogic Classpath elements and click the Add Project... button.
- Select your project, in this case the dev2dev-Article project.
With the classpath set up, let's update the Run Mode so that we can debug our application:
- While the configured WebLogic Server is stopped, double-click the server in the WebLogic Servers view to open the Edit WebLogic Server Instance dialog.
- Click the Runtime tab.
- Change the Run Mode to Debug Mode.
We're almost finished. All that is left is to perform is everything we've learned from start to finish then run the client that invokes the EJB and debug away. Here are the final steps:
- Start the server as mentioned above.
- Build the application as mentioned above (necessary only if you have not yet deployed the application to the running server or it is undeployed).
- Deploy the application as mentioned above (necessary only if you have not yet deployed the application to the running server or it is undeployed).
- Set a breakpoint at line 56 of
com.jwhitlock.ejb.HelloBean
(double-click in the left-hand gutter of the editor). - Run the
com.jwhitlock.HelloWorldClient
(right-click com.jwhitlock.HelloWorldClient > Run As > Java Application).
You should notice that Eclipse either notifies you of a breakpoint being hit or will automatically switch to the Debug perspective.
Figure 4 shows the Eclipse debugger stopping at the line where you set your breakpoint.
Figure 4. Eclipse debugger in action
Summary
And there you have it folks. We have learned how to successfully utilize the WebLogic-Plugin to manage a WebLogic Server's deployments and to debug those deployments. While the example in this article is extremely simple, it does cover the steps that you will always follow to manage and debug your WebLogic Servers and deployments regardless of deployment type.
Thanks for your time and I hope this helps ease the process of working with WebLogic in the Eclipse environment. For future features, project roadmap or anything else related to the WebLogic-Plugin, feel free to contact me or visit the WebLogic-Plugin home page.
References
- The home of the Eclipse platform
- Visit the Eclipse CodeShare Category for other Eclipse projects
Jeremy Whitlock is a consultant for CollabNet where he trains corporations on Subversion. He is also project owner of Dev2Dev's most popular project, eclipse-plugin, which provides extensions to Eclipse specifically for WebLogic Server.