How to pre-complie JSPs in Weblogic

This is one of the techniques I implemented in my last project, among others, to improve response time of JSPs in a Struts 2 based web application.

We know that, in any J2EE web application, the page load time is relatively high when we access the page for the first time because the container has to compile the JSP before presenting to the user. This is a performance bottleneck and gives the perception to the users that the system is slow.

To prevent this, we can precompile JSPs before deploying them in the server. WebLogic server offers two ways to pre-compile JSPs.

[1] Declarative Method
[2] Programmatic Method


[1] Declarative Method.

How to implement:

Add the following configuration to WEB-INF/weblogic.xml

<weblogic-web-app>

       ……….

 <jsp-descriptor>
       <jsp-param>
              <param-name>precompile</param-name>
              <param-value>true</param-value>
       </jsp-param>
 </jsp-descriptor>

       ……….

</weblogic-web-app>

Pros:

Easy to implement

Cons:

Precompilation happens at the time of deployment. This is a major disadvantage because:

(a) If any compilation error occurs, deployment will be halted at the point where the error occurred.
(b)The time taken for deployment will be very high if an application has more number of JSPs.
(c) Pre-compilation occurs every time the application is deployed, increasing the time of deployment.

[2] Programmatic Method.

Declarative method is not used for practical purposes for the disadvantages it has compared to its advantages.

Most efficient method for JSP precompilation is the programmatic method. This method eliminates the biggest disadvantage of declarative method – precompiling at deployment phase- and moves the precompilation process to development phase.

How to implement:

WebLogic provides a tool called weblogic.appc for precompiling JSPs.

Add the following ant target to the build.xml file

<target name="jspcompile">

<java classname="weblogic.appc" fork="yes">

<classpath path="${env.WL_HOME}\server\lib\weblogic.jar;${env.JAVA_HOME}\lib\tools.jar"/>

<arg line="-verbose -classpath '${dir.build}\requiredLibs.jar' '${dir.build}\demoApplication.war'" />

</java>

</target>

Some points to note:

(a) This task should execute after the task which creates WAR file because weblogic.appc expects a WAR file containing JSPs.
(b) Environment variables WL_HOME and JAVA_HOME should be set for ant to access environment variables using env.WL_HOME and env.JAVA_HOME
(c) dir.build is the project’s intermediate build directory where WAR file and any other JAR files etc are created.
(d) requiredLibs.jar is the library containing any classes used by JSPs. Multiple library files can be added as comma separated list.
(e) demoApplication.war is the WAR file where application’s JSPs reside.
(f) If you have spaces in dir.build , then use single quote(‘) as shown above. Otherwise ‘ are not required.

Pros:

(a) This method moves the precompilation to development phase so that any compilation errors are identified and corrected much before deployment.

(b) This method allows us to compile once deploy as many times as we want.

(c) This method reduced the deployment time significantly because precompilation is moved to development phase.

References:

1. http://download.oracle.com/docs/cd/E13222_01/wls/docs100/webapp/reference.html#wp57794

2. http://m-button.blogspot.com/2008/09/using-jsp-precompilation-in-weblogic.html

One thought on “How to pre-complie JSPs in Weblogic

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s