Friday, June 22, 2007

Configuring WebSphere to keep the Java code generated from a JSP

One of the more useful techniques you can use to debug the cause of a JSP compilation failure is to view the Java source code that the JSP engine generates from a JSP. You would think that WebSphere (Web's Fear as my colleague Solomon calls it) would make it easy to get the generated Java source - e.g. a checkbox in the WebSphere admin console - but you would be wrong.

Configuring WebSphere to leave JSP generated Java source is done on a per-application basis. It is switched on by modifying a parameter in the WebSphere-specific WEB-INF/ibm-web-ext.xmi deployment descriptor. This file is generated automatically by tools such as WSAD (aptly pronounced wah-sad) or by WebSphere when it installs an application.

The default WEB-INF/ibm-web.ext.xmi looks something like this:


<?xml version="1.0" encoding="UTF-8"?>
<webappext:WebAppExtension xmi:version="2.0" xmlns:xmi=http://www.omg.org/XMI
xmlns:webappext="webappext.xmi" xmlns:webapplication="webapplication.xmi" xmi:id="WebAppExtension_1"
reloadInterval="9"
reloadingEnabled="true"
defaultErrorPage="error.jsp"
additionalClassPath=""
fileServingEnabled="true"
directoryBrowsingEnabled="false"
serveServletsByClassnameEnabled="true"
autoRequestEncoding="true"
autoResponseEncoding="false"
<webApp href="WEB-INF/web.xml#MyWebApp"/>
<jspAttributes xmi:id="JSPAttribute_1" name="useThreadTagPool" value="true"/>
<jspAttributes xmi:id="JSPAttribute_2" name="verbose" value="false"/>
<jspAttributes xmi:id="JSPAttribute_3" name="deprecation" value="false"/>
<jspAttributes xmi:id="JSPAttribute_4" name="reloadEnabled" value="true"/>
<jspAttributes xmi:id="JSPAttribute_5" name="reloadInterval" value="5"/>
<jspAttributes xmi:id="JSPAttribute_6" name="keepgenerated" value="true"/>
<!-- <jspAttributes xmi:id="JSPAttribute_7" name="trackDependencies" value="true"/> -->
<jspAttributes xmi:id="JSPAttribute_8" name="jspCompileClasspath" value=""/>
</webappext:WebAppExtension>

To force WebSphere to leave the generated Java source you need to change the value of the keepgenerated attribute to true and restart your application. WebSphere should then leave the generated source in the "scratch dir" found under profile_root/temp.

More WebSphere JSP engine configuration parameters here.

No comments: