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







Easy to implement


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 '${}\requiredLibs.jar' '${}\demoApplication.war'" />



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) 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 , then use single quote(‘) as shown above. Otherwise ‘ are not required.


(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.




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

Leave a Reply

%d bloggers like this: