How to pre-complie JSPs in Weblogic

This is one of the tech­niques I imple­ment­ed in my last project, among oth­ers, to improve response time of JSPs in a Struts 2 based web appli­ca­tion.

We know that, in any J2EE web appli­ca­tion, the page load time is rel­a­tive­ly high when we access the page for the first time because the con­tain­er has to com­pile the JSP before pre­sent­ing to the user. This is a per­for­mance bot­tle­neck and gives the per­cep­tion to the users that the sys­tem is slow.

To pre­vent this, we can pre­com­pile JSPs before deploy­ing them in the serv­er. WebLog­ic serv­er offers two ways to pre-com­pile JSPs.

[1] Declar­a­tive Method
[2] Pro­gram­mat­ic Method


[1] Declar­a­tive Method.

How to imple­ment:

Add the fol­low­ing con­fig­u­ra­tion 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 imple­ment

Cons:

Pre­com­pi­la­tion hap­pens at the time of deploy­ment. This is a major dis­ad­van­tage because:

(a) If any com­pi­la­tion error occurs, deploy­ment will be halt­ed at the point where the error occurred.
(b)The time tak­en for deploy­ment will be very high if an appli­ca­tion has more num­ber of JSPs.
© Pre-com­pi­la­tion occurs every time the appli­ca­tion is deployed, increas­ing the time of deploy­ment.

[2] Pro­gram­mat­ic Method.

Declar­a­tive method is not used for prac­ti­cal pur­pos­es for the dis­ad­van­tages it has com­pared to its advan­tages.

Most effi­cient method for JSP pre­com­pi­la­tion is the pro­gram­mat­ic method. This method elim­i­nates the biggest dis­ad­van­tage of declar­a­tive method – pre­com­pil­ing at deploy­ment phase- and moves the pre­com­pi­la­tion process to devel­op­ment phase.

How to imple­ment:

WebLog­ic pro­vides a tool called weblogic.appc for pre­com­pil­ing JSPs.

Add the fol­low­ing ant tar­get 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 exe­cute after the task which cre­ates WAR file because weblogic.appc expects a WAR file con­tain­ing JSPs.
(b) Envi­ron­ment vari­ables WL_HOME and JAVA_HOME should be set for ant to access envi­ron­ment vari­ables using env.WL_HOME and env.JAVA_HOME
© dir.build is the project’s inter­me­di­ate build direc­to­ry where WAR file and any oth­er JAR files etc are cre­at­ed.
(d) requiredLibs.jar is the library con­tain­ing any class­es used by JSPs. Mul­ti­ple library files can be added as com­ma sep­a­rat­ed list.
(e) demoApplication.war is the WAR file where application’s JSPs reside.
(f) If you have spaces in dir.build , then use sin­gle quote(‘) as shown above. Oth­er­wise ‘ are not required.

Pros:

(a) This method moves the pre­com­pi­la­tion to devel­op­ment phase so that any com­pi­la­tion errors are iden­ti­fied and cor­rect­ed much before deploy­ment.

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

© This method reduced the deploy­ment time sig­nif­i­cant­ly because pre­com­pi­la­tion is moved to devel­op­ment phase.

Ref­er­ences:

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

Categories:

Tags:

One response to “How to pre-complie JSPs in Weblogic”

  1. […] How to pre-com­plie JSPs in Weblog­ic | chaitanya’s oth­er blog – WebLog­ic pro­vides a tool called weblogic.appc for pre­com­pil­ing JSPs. … requiredLibs.jar is the library con­tain­ing any class­es used by JSPs. Mul­ti­ple library files can be added as com­ma sep­a­rat­ed list. (e) … […]

Leave a Reply

%d bloggers like this: