Tuesday, November 25, 2014

WebLogic deployment time compilation


The WebLogic server can be configured to precompile your JSPs when a Web Application is deployed or re-deployed or when WebLogic Server starts.

1.     Configuring deployment time compilation

In weblogic.xml add the marked in yellow.

<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
                <context-root>applicationctx</context-root>
                <jsp-descriptor>
                                <precompile>true</precompile>
                                <precompile-continue>true</precompile-continue>
                </jsp-descriptor>
</weblogic-web-app>

The above will ensure deployment time compilation of the JSPs.

The verbose errors are displayed in the console log when precompile is set to true, regardless of the precompile-continue value.

Note
This feature needs to be tested with the applications. Some of the check performed may cause issues. Some errors may need to be fixed for deployment time compilation to be successful.

2.     Updating deployment time compilation using plan.xml

The below deployment plan updates the values of precompile and precompile-continue to false during deployment.

<deployment-plan xmlns="http://xmlns.oracle.com/weblogic/deployment-plan" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/deployment-plan http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd">
  <application-name>applicationctx</application-name>
  <variable-definition>
                                <variable>
                                                <name>Precompile_jsp</name>
                                                <value>false</value>
                                </variable>
                                <variable>
                                                <name>Precompile_continue_jsp</name>
                                                <value>false</value>
                                </variable>
                </variable-definition>
                <module-override>
                                <module-name>application-web-3.0.0.0.war</module-name>
                                <module-type>war</module-type>
                                <module-descriptor external="false">
                                                <root-element>weblogic-web-app</root-element>
                                                <uri>WEB-INF/weblogic.xml</uri>
                                                <variable-assignment>
                                                                <name>Precompile_jsp</name>
                                                                <xpath>/weblogic-web-app/jsp-descriptor/precompile</xpath>
                                                                <origin>planbased</origin>
                                                                <operation>replace</operation>
                                                </variable-assignment>
                                                <variable-assignment>
                                                                <name>Precompile_continue_jsp</name>
                                                                <xpath>/weblogic-web-app/jsp-descriptor/precompile-continue</xpath>
                                                                <origin>planbased</origin>
                                                                <operation>replace</operation>
                                                </variable-assignment>
                                </module-descriptor>
                </module-override>
  <config-root>D:\Users\sashwat.gupta\applicationctx\config</config-root>
</deployment-plan>


3.     Suggested Approach

  • Disable JSP compilation in weblogic.xml
  • Use development transition plan to enable this and test [this will ensure correctness of JSPs]
  • Disable in production deployment plan [To reduce the startup time for the applications]

4.     Identified issues in applications

4.1.                     Tag Imports

In an application the imports were mentioned as

<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>

These imports were incorrect as per specifications and were giving errors while deployment time compilation. This was corrected by changing to

<%@tag import="java.util.*"%>
<%@tag import="java.io.*"%>

Sample error in weblogic console:

weblogic.servlet.jsp.CompilationException: Captcha.tag:2:5: The page directive is not valid in tag files.
<%@ page import="java.util.*"%>
    ^--^
Captcha.tag:2:5: The page directive is not valid in tag files.
<%@ page import="java.util.*"%>
    ^--^
Captcha.tag:3:5: The page directive is not valid in tag files.
<%@ page import="java.io.*"%>
    ^--^
Captcha.tag:3:5: The page directive is not valid in tag files.
<%@ page import="java.io.*"%>
    ^--^
Captcha.tag:4:5: The page directive is not valid in tag files.
<%@ page import="javax.servlet.*"%>
    ^--^
Captcha.tag:4:5: The page directive is not valid in tag files.
<%@ page import="javax.servlet.*"%>
    ^--^

4.2.                     Tags not closed

<html:hidden property="property" value="${ property}"> was changed to

<html:hidden property="property" value="${ property}"/> to close the html tag.

4.3.                     Page Encoding provided multiple times

Due to JSP includes the page encoding was being imported multiple times.
<%@ page pageEncoding="utf-8" %>

The page encoding was made unique and only put in the header jsp to solve the issue.