Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Jetty/Feature/Jetty Jspc Maven Plugin

< Jetty‎ | Feature
Revision as of 07:30, 23 September 2009 by Janb.webtide.com (Talk | contribs) (Precompiling Jsps with Overlaid Wars)

Jetty Jspc Maven Plugin

This plugin will help you pre-compile your jsps and works in conjunction with the maven war plugin to put them inside an assembled war.


Configuration

Here's the basic setup required to put the jspc plugin into your build:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
   <artifactId>jetty-jspc-maven-plugin</artifactId>
   <version>7.0.0</version>
   <executions>
     <execution>
       <id>jspc</id>
       <goals>
         <goal>jspc</goal>
       </goals>
       <configuration>
       </configuration>
     </execution>
   </executions>
 </plugin>

Configurable Parameters

The configurable parameters are

Parameter Name Default Value Meaning
webXmlFragment "${basedir}/target/webfrag.xml" File into which to generate the servlet declarations. Will be merged with an existing web.xml.
packageRoot "jsp" Default root package name for all generated classes.
webAppSourceDirectory "${basedir}/src/main/webapp" Root of resources directory where jsps, tags etc are located.
webXml "${basedir}/src/main/webapp/WEB-INF/web.xml" The web.xml file to use to merge with the generated fragments.
includes "**\/*.jsp, **\/*.jspx" The comma separated list of patterns for file extensions to be processed.
excludes "**\/.svn\/**" The comma separated list of patterns for file extensions to be skipped.
classesDirectory "${project.build.outputDirectory}" Location of classes for the webapp.
generatedClasses "${project.build.outputDirectory}" Location to put the generated classes for the jsps.
keepSources false Controls whether or not .java files generated during compilation will be preserved.
validateXml false x
suppressSmap true Whether or not to generate JSR45 compliant debug info.
ignoreJspFragmentErrors false x
schemaResourcePrefix x
insertionMarker x
verbose false x
mergeFragment true x

Taking all the default settings, here's how to configure the war plugin to use the generated web.xml that includes all of the jsp servlet declarations:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <webXml>${basedir}/target/web.xml</webXml>
  </configuration>
</plugin>

Precompiling Jsps with Overlaid Wars

Precompiling jsps with an overlaid war requires a bit more configuration. This is because you need to separate the steps of unpacking the overlaid war and then repacking the final target war so the jetty-jspc-maven-plugin has the opportunity to access the overlaid resources.

In the example we'll show, we will use an overlaid war. The overlaid war will provide the web.xml file but the jsps will be in src/main/webapp (ie part of the project that uses the overlay). We will unpack the overlaid war file, compile the jsps and merge their servlet definitions into the extracted web.xml, then war up the lot.

Here's an example configuration of the war plugin that separate those phases into an unpack phase, and then a packing phase:

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack</id>
            <goals><goal>exploded</goal></goals>
            <phase>generate-resources</phase>
            <configuration>
              <webappDirectory>target/foo</webappDirectory>
              <overlays>
                <overlay />
                <overlay>
                  <groupId>org.eclipse.jetty</groupId>
                  <artifactId>test-jetty-webapp</artifactId>
                </overlay>
              </overlays>
            </configuration>
          </execution>
          <execution>
            <id>pack</id>
            <goals><goal>war</goal></goals>
            <phase>package</phase>
            <configuration>
              <warSourceDirectory>target/foo</warSourceDirectory>
              <webXml>target/web.xml</webXml>
            </configuration>
          </execution>
        </executions>
      </plugin>


Now you also need to configure the jetty-jspc-maven-plugin so that it can use the web.xml that was extracted by the war unpacking and merge in the generated definitions of the servlets. This is in target/foo/WEB-INF/web.xml. Using the default settings, the web.xml merged with the jsp servlet definitions will be put into target/web.xml.


      <plugin>
          <groupId>org.mortbay.jetty</groupId>
          <artifactId>jetty-jspc-maven-plugin</artifactId>
          <version>${project.version}</version>
          <executions>
            <execution>
              <id>jspc</id>
              <goals>
                <goal>jspc</goal>
              </goals>
              <configuration>
                 <webXml>target/foo/WEB-INF/web.xml</webXml>
                 <includes>**/*.foo</includes>
                 <excludes>**/*.fff</excludes>
              </configuration>
            </execution>
          </executions>
        </plugin>

Back to the top