How to debug Java EE application using WebLogic 10.3
Asked Answered
C

6

6

I am using WebLogic 10.3 with a Java EE application. Can anyone please tell me how to debug this application?

Cottier answered 18/2, 2011 at 15:2 Comment(0)
C
11

I think the other answers are somewhat wrong. For windows, if you setup an environment variable called debugFlag to be true or in solaris/unix do the same

debugFlag=true
export debugFlag
DEBUG_PORT=8453
export DEBUG_PORT

, then setDomainEnv.sh or setDomainEnv.cmd are going to be called to start WLS by the other scripts. They look for the debugFlag and DEBUG_PORT, as long as the "production" flag is not set it will pick up the right parameters from the script for debugging (-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=%DEBUG_PORT%,server=y,suspend=n -Djava.compiler=NONE).

YOU SHOULD NOT BE HACKING THESE SCRIPTS. It's going to make deployment and maintenance hard, the entire purpose of the setDomainEnv script is so that the right defaults are used and maintained across the cluster and throughout the entire environment. They are poorly documented I admit.

Note, if you are using the Oracle weblogic maven plugin, the target wls:deploy or wls:start-server will then pick up those environment settings when starting because they call the commands under the hood, and those in turn first call setDomainEnv.

As of right now, if you are using eclipse and have set up a Oracle WebLogicServer, the maven plugin will not attach to it into debug mode when you issue a mvn:deploy, you can either restart it in debug mode (silly), or create a 'Run ==> Debug ==> DebugConfigurations ==> RemoteJavaApplication' with a connection type of 'standard (socket attach)', a host of 'localhost' (or the remote server) and a port (default for me is '8453'). You can then do Run ==> Debug Configurations ==> Local Server Attach.

Compline answered 7/2, 2014 at 21:25 Comment(0)
P
6

For me this worked:

In the folder WEBLOGIC_HOME\user_projects\domains\my_domain\bin

There is a file setDomainEnv.cmd

In it I found the code:

if "%debugFlag%"=="true" (
    set JAVA_DEBUG=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=%DEBUG_PORT%,server=y,suspend=n -Djava.compiler=NONE
    set JAVA_OPTIONS=%JAVA_OPTIONS% %enableHotswapFlag% -ea -da:com.bea... -da:javelin... -da:weblogic... -ea:com.bea.wli... -ea:com.bea.broker... -ea:com.bea.sbconsole...
) else (
    set JAVA_OPTIONS=%JAVA_OPTIONS% %enableHotswapFlag% -da
)

I just put the lines for debug outside the if clause:

set JAVA_DEBUG=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=%DEBUG_PORT%,server=y,suspend=n -Djava.compiler=NONE
set JAVA_OPTIONS=%JAVA_OPTIONS% %enableHotswapFlag% -ea -da:com.bea... -da:javelin... -da:weblogic... -ea:com.bea.wli... -ea:com.bea.broker... -ea:com.bea.sbconsole...

    if "%debugFlag%"=="true" (
        set JAVA_DEBUG=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=%DEBUG_PORT%,server=y,suspend=n -Djava.compiler=NONE
        set JAVA_OPTIONS=%JAVA_OPTIONS% %enableHotswapFlag% -ea -da:com.bea... -da:javelin... -da:weblogic... -ea:com.bea.wli... -ea:com.bea.broker... -ea:com.bea.sbconsole...
    ) else (
        set JAVA_OPTIONS=%JAVA_OPTIONS% %enableHotswapFlag% -da
    )

After these settings you can debug on port 8453

The port is also configured in this file, you can also change it:

if "%DEBUG_PORT%"=="" (
    set DEBUG_PORT=8453
)

Stop the server, run the script, start the server.

Now your weblogic server is setup for debugging.

Pretence answered 15/6, 2012 at 7:15 Comment(1)
That's wrong, and not scale able or maintainable, the debugFlag is to be set in the environment, along with the port. The only caveat is that in production environments that flag is ignored, even if set.Compline
S
4

The best approach to enable debug on weblogic server is as follows:

  • create a script file
  • put these lines into your script (for windows):

set debugFlag=true

set DEBUG_PORT=9001

  • call the start script (e.g.): C:\Oracle\Middleware\user_projects\domains\domain1\bin\startWebLogic.cmd)

So, there will be 3 lines on the script, that's all you need...

There are also more variables you can use....

WLS_REDIRECT_LOG=log_path <- redirect output to a file instead of console window...

JAVA_OPTIONS <- more options for the JVM

EXTRA_JAVA_PROPERTIES <- define aditional properties you may need

Sago answered 14/8, 2013 at 10:19 Comment(0)
S
3

What I did to get the Eclipse Debugger working with Weblogic 10 was to lookup the startWeblogic.cmd file in the folder weblogic.10.3.3.0\user_projects\domains\base_domain\bin\ and modify the following line (around line 95):

set JAVA_OPTIONS=%SAVE_JAVA_OPTIONS%

to

set JAVA_OPTIONS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8453,server=y,suspend=n %SAVE_JAVA_OPTIONS%

Then I stopped any weblogic server that was running from within Eclipse and started Weblogic using the startWebLogic.cmd file.

Then I created a new debug configuration in Eclipse. Go to debug configurations, choose 'Remote Java Application', it should recognize your project, use Standard (Socket attach) for the connection type and specify port 8453 in the connection properties.

Now apply and run. Set some breakpoints in a piece of code that will regularly run and see if it is working.

Slave answered 5/6, 2012 at 8:6 Comment(1)
This did not work for me and in fact WebLogic would not start after I tried it.Milne
L
0

Jonnathan Q answer helped me to launch Weblogic in debug mode also. For unix you can use the syntax like this in shell scripts:

debugFlag=true
export debugFlag
DEBUG_PORT=9001
export DEBUG_PORT

and then run startWeblogic.sh and startManagedWeblogic.sh if necessary.

UPDATE: to make our IDEs (Eclipse, IDEA) to stop on breakpoints we deployed our webapp on AdminServer, because in case of deploying to the node in clustered environment our IDEs didn't stop at breakpoints at all.

Limited answered 29/11, 2013 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.