Precompile JSP

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
 
Line 5: Line 5:
 
Resin provides JspPrecompileListener that causes JSP to be compiled when the web application starts.
 
Resin provides JspPrecompileListener that causes JSP to be compiled when the web application starts.
  
== JspPrecompileListener ==
+
== JspPrecompileListener [[http://www.caucho.com/resin-4.0-javadoc/com/caucho/jsp/JspPrecompileListener.html javadoc]] ==
  
javadoc: [[http://www.caucho.com/resin-4.0-javadoc/com/caucho/jsp/JspPrecompileListener.html]]
+
{|border="1"
 +
|-
 +
! Attribute !! Description !! Type !! Default
 +
|-
 +
| extension || An extension to precompile || String || jsp
 +
|-
 +
| fileset || A fileset for complex matching || FileSetType || none
 +
|-
 +
| timeout || The time to wait for compilation to complete || Period || 60s
 +
|}
  
 
The following configuration causes Resin to compile all files in the web-app that have an extension of .jsp or .jspx when the application first starts.
 
The following configuration causes Resin to compile all files in the web-app that have an extension of .jsp or .jspx when the application first starts.
Line 27: Line 36:
  
 
resin.xml
 
resin.xml
</pre>
+
<pre>
 
<web-app-default>
 
<web-app-default>
 
   <listener>
 
   <listener>
Line 34: Line 43:
 
</web-app-default>
 
</web-app-default>
 
</pre>
 
</pre>
 +
 
You can also use a <fileset> for more control over which jsp are precompiled:
 
You can also use a <fileset> for more control over which jsp are precompiled:
  

Latest revision as of 13:09, 9 December 2011


Unless explicitly compiled ahead of time, JSP files are compiled the first time they are accessed. On large production sites, or in situations involving complicated JSP files, compilation may cause unacceptable delays to users first accessing the JSP page.

Resin provides JspPrecompileListener that causes JSP to be compiled when the web application starts.

[edit] JspPrecompileListener [javadoc]

Attribute Description Type Default
extension An extension to precompile String jsp
fileset A fileset for complex matching FileSetType none
timeout The time to wait for compilation to complete Period 60s

The following configuration causes Resin to compile all files in the web-app that have an extension of .jsp or .jspx when the application first starts.

WEB-INF/web.xml

<web-app xmlns="http://caucho.com/ns/resin">
  <listener>
    <listener-class>com.caucho.jsp.JspPrecompileListener</listener-class>
    <init>
      <extension>jsp</extension>
      <extension>jspx</extension>
    </init>
  </listener>
</web-app>

It can also be configured in resin.xml to apply to all web-apps.

resin.xml

<web-app-default>
  <listener>
    <listener-class>com.caucho.jsp.JspPrecompileListener</listener-class>
  </listener>
</web-app-default>

You can also use a <fileset> for more control over which jsp are precompiled:

resin.xml

<web-app>
  <listener>
    <listener-class>com.caucho.jsp.JspPrecompileListener</listener-class>
    <init>
      <fileset>
        <include>**/*.jsp</include>
        <exclude>/a.jsp</exclude>
        <exclude>/foo/c.jsp</exclude>
      </fileset>
    </init>
  </listener>
</web-app>

The first line includes all jsp's, it's the same as specifying jsp. The following lines exclude specific jsp.

[edit] JSPC

As an alternative, Resin also provides a jspc command line that is used to explicitly compile JSP files before they are accessed for the first time.

Command line

unix> ./bin/resin.sh jspc
usage: com.caucho.jsp.JspCompiler [flags] jsp1 jsp2 ...
 -app-dir  : The directory root of the web-app.
 -class-dir: The working directory to use as output.
 -compiler: sets the javac.
 -conf: A configuration file for the compiler.
Personal tools