开发者

How to debug Java EE application using WebLogic 10.3

I am using WebLogic 10.3 with a Java EE application. Can anyone please tell me how to de开发者_StackOverflowbug this application?


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.


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.


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


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.


Try remote debugging the application. You can try these links, thay may be helpful:

http://download.oracle.com/docs/cd/E15051_01/wlw/docs103/guide/ideuserguide/servers/conWebLogicServer.html#DebugRemote

http://eclipse.sys-con.com/node/169364

http://www.jacoozi.com/index.php?option=com_content&task=view&id=119&Itemid=134


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜