comments 7

JSP Precompilation For Maven2 Project

You can precompile JSP as part of your Maven2 project build by using Maven2 JSPC Plugin.

Follow the usage guide for copy-paste samples to add insert-fragment in web.xml file and jspc-maven-plugin + maven-war-plugin as part of build plugins in pom.xml file.

Here are some problems that I encountered while adding JSP precompilation to Wish:

Some of the JSPs use SiteMesh taglib and since the application only needed it as part of the war package, I originally set the dependency scope to be runtime. This causes JSPC to complain because it needs the library in the classpath while compiling the JSPs.

Embedded error: file:E:/tazmania/eclipse-workspace/wish/src/main/webapp/404.jsp(1,1)
The absolute uri: http://www.opensymphony.com/sitemesh/decorator cannot be resolved
in either web.xml or the jar files deployed with this application

The solution is to change the scope from runtime to compile so SiteMesh becomes available during JSP precompilation.

The next problem is with JSP API and Jasper Runtime.

E:tazmaniaeclipse-workspacewishtargetjsp-sourcejsplogin_jsp.java:[194,68]
cannot resolve symbol
symbol  : class JspTag
location: package tagext

E:tazmaniaeclipse-workspacewishtargetjsp-sourcejsp_404_jsp.java:[7,61]
package org.apache.jasper.runtime does not exist
The solution is to add the missing libraries as dependencies in pom.xml file.

<dependency>
  <groupId>tomcat</groupId>
  <artifactId>jasper-runtime</artifactId>
  <version>5.5.12</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.0</version>
  <scope>compile</scope>
</dependency>

Note that you might want to specify the library versions based on the target environment you’re going to deploy the application to.

About these ads

7 Comments

  1. Martin Gilday

    Thanks for this. I just had to make a slight change to use the jstl libraries.

    taglibs
    standard
    1.1.2

    jstl
    jstl
    1.1.2

  2. Martin Gilday

    Sorry that took out the xml formatting.
    It was 2 dependencies (groupId, artifactId, version)

  3. Grzegorz Loniewski

    The problem: Embedded error: file:E:/tazmania/eclipse-workspace/wish/src/main/webapp/404.jsp(1,1)
    The absolute uri: http://www.opensymphony.com/sitemesh/decorator cannot be resolved
    in either web.xml or the jar files deployed with this application is not olny ptoblem with the scope.. I ve changed it to compile and still the same error occurs… Thanks in advance for some new suggestion.

    Greg

  4. Viktor Nordling

    Hi,

    I’m trying to use the Maven jspc plugin, but compilation fails because it uses version 1.4 of Java and I need 5.0. I cannot figure out how to change it.

    Any ideas?

    Thanks!

  5. Anand

    To use java 1.5 for compiling your JSPs,

    org.codehaus.mojo
    jspc-maven-plugin
    1.4.6

    jspc

    compile

    1.5
    1.5
    1.5
    true

  6. Pingback: maven ile jsp precompile i┼člemi | /home/haqen

Leave a Reply

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