Debugging Server-side Code through IntelliJ IDEA with BEA Weblogic 8.1

by Mark Spritzler

In order to debug server-side code you must start your (app) server in debug mode, and you must have your IDE connect to the remote JVM through a Remote Server Debug configuration (That's what it is called in IDEA). Other IDE's should have something very similar to this that will allow it to "hook" into the remote JVM and find out the calls that are being made, and to stop the code when it hits a breakpoint that you have set in the IDE.

How to create a "Remote Server Debug configuration".

  1. Select the "run" menu, and choose "edit configuration".

  1. Select the Remote Tab

  1. Click on the plus sign to add a new configuration.
  2. Change the name of the configuration to something meaningful like "RemoteServerDebug"

  1. Copy the command line arguments in the middle of the screen.
    1. Example: -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

This command line is what is needed to start the Application Server in debug mode, see "To set the server to startup in debug mode."

  1. Click OK, and your IDE configuration is now complete.

To set the server to startup in debug mode.

  1. Edit c:\bea\weblogic\common\commEnv.cmd
    1. Find the JAVA_OPTIONS statement and paste what you copied from the IntelliJ IDEA Remote configuration screen.
    2. Or you can copy the following

-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n

This code is a little different than what you get from IntelliJ, but when I was setting up my machine, I ran into a problem and using the above worked for me. However, I would try using what you get from IntelliJ IDEA first, as that is what should be in the JAVA_OPTIONS.

Example of the commEnv.cmd file where JAVA_OPTIONS is listed

set JAVA_OPTIONS=%JAVA_OPTIONS% -Xverify:none -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n

After changing the file, start or restart your App Server. When it restarts it will be in debug mode.

Setting a breakpoint and watching IntelliJ IDEA stop the code in action. J

  1. Go to any server side code that you want to debug. Click on the left side of the code to create a breakpoint.

As you can see the red ball/dot on the left of the code is a breakpoint.

  1. Select your Remote configuration from the dropdown in the toolbar.

  1. Click the Green arrow with the bug in the icon button.

  1. Click the Debug button, if you had had the "Display settings before running/debugging checkbox selected. If this was deselected, you would not see the screen above.
  1. You will now see the debug window at the bottom of the screen.

  1. Now IntelliJ IDEA is ready to debug the serverside code, when that code actually gets called on the App Server.
  1. Go to a DOS prompt and kick off your client code that calls this method. When the code reaches the line where there is a breakpoint, IntelliJ IDEA will stop the server from running more code, and now you can step through the code and see variable values, etc. Just like a real debugger. J

Congratulations, see now wasn't that simple. J

Debugging on other IDEs.

Now that we have covered how to set up and start a debugging session with IntelliJ IDEA and Weblogic server, lets talk about the other IDEs, like Eclipse, and Netbeans, and other Web Servers like JBoss and Websphere.

These are just as simple. The configuration is almost identical. The only difference is what names they call their debugging configuration, in the case of the IDEs and which text configuration file the App server stores the call to the java command to start their server, and then include the X parameters to that line.

In Eclipse, their debug configuration is called "Remote Java Application" which you will see after clicking the Green bug button on the toolbar. And just like in IntelliJ IDEA< you just give it a meaningful name. In IntelliJ IDEA, their Java_options for the server uses port 5005, but in Eclipse it is set for port 8000. Don't worry about this, as it is just a formality, and the only worry would be that you choose a port that is already in use. Either one of these ports will work fine for your configuration, they just have to match from on both sides.

Restart your app server, set a breakpoint, and run your program in a DOS prompt, and bingo, you are stepping through code.

For more information on your IDE or App Server, please check their respective websites and other documentation. Now that you know the basics, it shouldn't be hard to find more specific information. It is one of Murphy's law, that you can't find the information you want when you need it, but after you figure it out, you find the information everywhere.

Good Luck and happy debugging. May all your bugs be easy to find.