Thursday, April 9, 2015

How to setup remote debug with WebLogic and Eclipse

Setup remote debug with WebLogic and Eclipse

As always there is the clean way, and the one-off way.
We will see how to setup debug for weblogic using the clean way which is to leverage all the built-in items already present but not clear that they are.

<domain>/bin/setDomainEnv.sh has interesting items: 

  • First there is the debugFlag="true"
  • Then there is DEBUG_ PORT="8453"
  • Then you will also see:
JAVA_DEBUG="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=${DEBUG_PORT},server=y,suspend=n -Djava.compiler=NONE

So the clean answer lies somewhere between these three. Also while there is the command line option as well (as you can see at the bottom of the setDomainEnv.sh).

Note: In production mode the debug is disabled by default by unsetting the flag. We can however get around this by re-setting the flag after this piece of code.

So here are the steps

Set the debug Flag

After around line number 203 in setDomainEnv.sh add the lines (ignore echo if you don't want the noise). This will also get around the production mode issue mentioned above

Add after this block (around Line 203):
if [ "${PRODUCTION_MODE}" = "true" ] ; then
        debugFlag="false"
        export debugFlag
        testConsoleFlag="false"
        export testConsoleFlag
        iterativeDevFlag="false"
        export iterativeDevFlag
        logErrorsToConsoleFlag="false"
        export logErrorsToConsoleFlag
fi
echo "Setting debug flag"
export debugFlag="true"

If you are not using just the Admin Server:

If your deployment is using a specific managed server, then you can modify the above as:
if [ "${SERVER_NAME}" = "mgdserver1" ] ; then
      echo "Setting debug flag for mgdserver1"
      export debugFlag="true"
fi

If you have to remote debug more than one managed server

The above block also allows you to specify a different port number for this server. And you can duplicate the same block for each of your servers if needed.
if [ "${SERVER_NAME}" = "mgdserver1" ] ; then
      echo "Setting debug flag for mgdserver1 and port to 8454"
      export debugFlag="true"
      export DEBUG_PORT="8454"
fi

Eclipse setup

In Eclipse the setup is simple.
  • Right click on the Project containing the deployed items. Select "Debug as">"Debug Configurations"
  • Locate "Remote Java Application" in the list on the left
  • Create a new configuration with hostname and debug port of the weblogic server