How do I precompile my jsps?
Author: Deron Eriksson
Description: This tutorial describes how to precompile your JSPs using the maven jspc plugin.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1) || Tomcat 6.0.14


Page: < 1 2

(Continued from page 1)

If we examine the project's target directory, we can see that the index.jsp was indeed precompiled.

index.jsp has been precompiled

If we examine the target web.xmlW file, we can see that it contains the servletW and servlet mapping entries for the index.jsp compiled file. This is the web.xml file that gets packaged into the target/mywebapp.war file.

web.xml (target/mywebapp/WEB-INF/web.xml)

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	version="2.5">
	<display-name>My Web App</display-name>
	<servlet>
		<description></description>
		<display-name>TestServlet</display-name>
		<servlet-name>TestServlet</servlet-name>
		<servlet-class>my.TestServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>TestServlet</servlet-name>
		<url-pattern>/test</url-pattern>
	</servlet-mapping>

<!--
Automatically created by Apache Jakarta Tomcat JspC.
Place this fragment in the web.xml before all icon, display-name,
description, distributable, and context-param elements.
-->

    <servlet>
        <servlet-name>jsp.index_jsp</servlet-name>
        <servlet-class>jsp.index_jsp</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>jsp.index_jsp</servlet-name>
        <url-pattern>/index.jsp</url-pattern>
    </servlet-mapping>

<!--
All session-config, mime-mapping, welcome-file-list, error-page, taglib,
resource-ref, security-constraint, login-config, security-role,
env-entry, and ejb-ref elements should follow this fragment.
-->
</web-app>

This has been a short demonstration of how easy it is to use the mavenSW jspc plugin to precompile the jspsW in a project.

Page: < 1 2