Weblogic Debug

weblogic

Options to debug JSP:

  1. Set the breakpoint as we normal do when we debug a regular .java file. Restart the server in debug mode.
  2. Run > Debug
  3. Debug As > Debug on Server.
  4. Run > Debug As > Debug on Server.
  5. Before you can debug JSPs, you need to install the Eclipse WebTools. You can do this through the Callisto Update Site (click here to what a demonstration), or you can just download an all-in-one (Eclipse + everything you need for web development) here. https://waynebeaton.wordpress.com/2006/07/11/debugging-jsps-using-eclipse-webtools/
  6. http://www.eclipse.org/webtools/initial-contribution/IBM/evalGuides/ServerToolsEval.html
  7. https://www.youtube.com/watch?v=XdjGQVav10M
  8. https://www.jvmhost.com/articles/remotely-debug-java-jsp-eclipse/
  9. https://www.guru99.com/debug-jsp.html

What are limitations with debugging JSP files?

It is possible to debug JSP code, but it is a bit limited. We cannot set breakpoint inside JSP page. In general, JSP page is only intended to contain logic to render the page. Other Java code that are inside a JSP page should be moved into a .java file.

What are the overall things that we have to do to enable remote debugging?

  1. Make appropriate modification to WebLogic startWebLogic.cmd (See below)
  2. Make appropriate modification to your build.xml to enable debugging (See below)
  3. Configure Eclipse to enable debugging (See below)

What modification do we have to do in startWebLogic.cmd in order to debug?

Put these lines into startWebLogic.cmd (the one that is inside the bin folder):

set DEBUG_OPT=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n

Make sure that you put %DEBUG_OPT% into the line that actually start WebLogic.

What modification do we need to make to build.xml to enable debugging?

Make sure that your build.xml contains debug="yes", and optimize="no"

How can we configure Eclipse to enable debugging?

In Eclipse, select "Run" -> "Debug Configuration". Double click on "Remote Java Application", then click on the project you want to debug. Supply the Host (localhost) and port number (1044). Click on "Apply", and click on "Debug"

What to do if you receive error?

  • The port number that you specified in DEBUG_OPT must match the port number you specified when you configure Eclipse, and this port number must be different from the one that your WebLogic uses. When you receive error, try to change the port number that you used in DEBUG_OPT and in Eclipse configuration (they must be the same)
  • In startWebLogic.cmd, make sure that %DEBUG_OPT% is added to the line that actually start WebLogic.
  • If you change the port number a few times but still cannot get debugging to work, consider disabling your firewall or configuring your firewall to allow the port number.

How can we set break points?

When debugging PHP with XDebug, XDebug has configuration that allows us specify that the debugger should pause on the first line of executable code. This is handy if we do not know which code is getting executed. Eclipse, on the other hand, does not seem to have this option. With Eclipse, we need to know what code is getting executed, so that we can set breakpoint. For example, if we are trying to debug something in the generic module, we should set breakpoint in the realService method in generic/src/com/quantros/controller/Controller.java

To set breakpoints in the Package Explorer view of the Java perspective, double-click the selected source code file to open it in an editor. Walk through the code and place your cursor on the marker bar (along the left edge of the editor area) on the line with the suspected code. Double-click to set the breakpoint.

Now go your browser, and reload the page, Eclipse should flash in the System tray. Switch to Eclipse. Now you can examine the code line by line.

How can we debug JSP file?

It is not easy to understand the exceptions that are generated from inside a JSP file. The line numbers reported by the stack trace do not match the line numbers in the JSP file. Fortunately, we can get around this problem. If you are using WebLogic 8.1, make sure that your weblogic.xml file contains:

  <jsp-descriptor>
        <jsp-param>
            <param-name>compileFlags</param-name>
            <param-value>-g</param-value>
        </jsp-param>
        <jsp-param>
            <param-name>keepgenerated</param-name>
             <param-value>true</param-value>
        </jsp-param>
        <jsp-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
        </jsp-param>

    <jsp-param>
      <param-name>printNulls</param-name>
      <param-value>false</param-value>
    </jsp-param>
    <jsp-param>
      <param-name>compileCommand</param-name>
      <param-value>C:\bea\jrockit81sp6_142_10\bin\javac</param-value>
    </jsp-param>
    <jsp-param>
      <param-name>workingDir</param-name>
      <param-value>C:\bea\user_projects\domains\domainName\myserver\classfiles</param-value>
    </jsp-param>
  </jsp-descriptor>

If you are using WebLogic 12c, instead of the above code, your weblogic.xml file should contain:

    <jsp-descriptor>
        <keepgenerated>true</keepgenerated>
        <print-nulls>false</print-nulls>
        <page-check-seconds>60</page-check-seconds>
    </jsp-descriptor>

or keep this in the web.xml file:

<context-param>
    <param-name>weblogic.jsp.keepgenerated</param-name>
    <param-value>true</param-value>
</context-param>

This tells WebLogic to keep the corresponding generated .java file with the corresponding line numbers in the JSP file. This will help us determine the line number in the JSP file that is causing the exception. We will have to manually go to the folder containing the generated .java file, open up the generated .java file and manually co-related the line numbers that are stored in generated .java file against the line numbers mentioned in the stack trace.

How can we evaluate some Java code while debugging?

  • Use the Display view, or highlight the code you want to run and right-click/Execute or Ctrl+U. Window -> Show View -> Display. If you run code like System.out.println(path.length), you may need to switch to the Console view to see the result.
  • Use the "watch expressions" feature. Just mark the piece of code in the source code view, right-click and select "Watch".
  • If you highlight the expression in the Display view (which also allows content assist, btw), you can right-click and choose "inspect" (runs the expression and brings up an inspector tree on the result), "execute" (runs the expression), and "display" (runs the expression and prints the result)

What else do I want to know?

I want to know:

  • How to set breakpoint inside the JSP file (if I cannot move Java code outside of the JSP file). I know the location of the corresponding generated .java file from above, can I open it in Eclipse and set break point in there? I may have to make the request twice. The first one is to generate the .java file. After the .java file is created, I maybe able to open it with Eclipse and set the break-point inside it
  • How to start debugging when an exception occur rather than having to determine the first java file executed
  • If you know a better way to debug JSP code, please update this page or add it as a comment on this page.

How can we debug WebLogic JSP / Servlet?

Put these lines into startWebLogic.cmd:

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

make sure that your build.xml contains debug="yes", and optimize="no"

and in Eclipse, select "Run" -> "Debug Configuration". Double click on "Remote Java Application", then click on the project you want to debug. Supply the Host (localhost) and port number (1044). Click on "Apply", and click on "Debug"

When debugging PHP with XDebug, XDebug has configuration that allows us specify that the debugger should pause on the first line of executable code. This is handy if we do not know which code is getting executed. Eclipse, on the other hand, does not seem to have this option. With Eclipse, we need to what code is getting executed, so that we can set breakpoint. To set breakpoints in the Package Explorer view of the Java perspective, double-click the selected source code file to open it in an editor. Walk through the code and place your cursor on the marker bar (along the left edge of the editor area) on the line with the suspected code. Double-click to set the breakpoint.

If you get "connection refused" when you start your debug session, check to see if the port that you specified is already being used by another program. To do this, shutdown your WebLogic, run:

netstat -a

This will display the ports that are being used. If the port that you specified is being used by another program, you can specify another port.

It is not easy to understand the exceptions that are generated from inside a JSP file. The line numbers reported by the stack trace do not match the line numbers in the JSP file. Fortunately, we can get around this problem. If you are using WebLogic 8.1, make sure that your weblogic.xml file contains:

  <jsp-descriptor>
        <jsp-param>
            <param-name>compileFlags</param-name>
            <param-value>-g</param-value>
        </jsp-param>
        <jsp-param>
            <param-name>keepgenerated</param-name>
             <param-value>true</param-value>
        </jsp-param>
        <jsp-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
        </jsp-param>

    <jsp-param>
      <param-name>printNulls</param-name>
      <param-value>false</param-value>
    </jsp-param>
    <jsp-param>
      <param-name>compileCommand</param-name>
      <param-value>C:\bea\jrockit81sp6_142_10\bin\javac</param-value>
    </jsp-param>
    <jsp-param>
      <param-name>workingDir</param-name>
      <param-value>C:\bea\user_projects\domains\quantrosDev\myserver\classfiles</param-value>
    </jsp-param>
  </jsp-descriptor>

This tells WebLogic to keep the corresponding generated .java file with the corresponding line numbers in the JSP file. This will help us determine the line number in the JSP file that is causing the exception. I want to be able to:

  • set breakpoint inside the JSP file
  • start debugging when an exception occur rather than having to determine the first java file executed

I may have to set breakpoint inside the generated JSP file (I may have to make the request twice. The first one is to generate the .java file. After the .java file is created, I maybe able to open it with Eclipse and set the break-point inside it).

http://docs.oracle.com/cd/E13226_01/workshop/docs92/studio32/IDEUserGuide/WebLogicServer.html#DebugRemote
http://docs.oracle.com/cd/E13224_01/wlw/docs102/guide/ideuserguide/servers/conWebLogicServer.html#DebugRemote
http://objectmix.com/weblogic/543960-debugging-jsp-weblogic-9-2-eclipse-3-2-1-plugin.html
http://stackoverflow.com/questions/8212633/debugging-jsp-pages-in-weblogic
http://stackoverflow.com/questions/5583883/how-to-attach-sources-for-jsp-debugging-with-eclipse

http://www.ibm.com/developerworks/library/os-ecbug/

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License