blob: e0cbe87f80b68e52704a70db18b55e39ceeace73 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Jetty Jspc Maven Plugin</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty : The Definitive Reference"><link rel="up" href="maven-and-jetty.html" title="Chapter&nbsp;21.&nbsp;Maven and Jetty"><link rel="prev" href="jetty-maven-scanning.html" title="Files Scanned by the Jetty Maven Plugin"><link rel="next" href="ant-and-jetty.html" title="Chapter&nbsp;22.&nbsp;Using Ant with Jetty"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><script type="text/javascript" src="js/shCore.js"></script><script type="text/javascript" src="js/shBrushJava.js"></script><script type="text/javascript" src="js/shBrushXml.js"></script><script type="text/javascript" src="js/shBrushBash.js"></script><script type="text/javascript" src="js/shBrushJScript.js"></script><script type="text/javascript" src="js/shBrushSql.js"></script><script type="text/javascript" src="js/shBrushProperties.js"></script><script type="text/javascript" src="js/shBrushPlain.js"></script><link type="text/css" rel="stylesheet" href="css/shCore.css"><link type="text/css" rel="stylesheet" href="css/shThemeEclipse.css"><link type="text/css" rel="stylesheet" href="css/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.3.0.v20150612</span></td><td style="width: 50%"><script type="text/javascript"> (function() {
var cx = '016459005284625897022:obd4lsai2ds';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script><gcse:search></gcse:search></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Jetty Jspc Maven Plugin</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jetty-maven-scanning.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;21.&nbsp;Maven and Jetty<br><a accesskey="p" href="index.html"><i class="icon-home"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ant-and-jetty.html">Next <i class="icon-chevron-right"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ...
scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="jetty-jspc-maven-plugin"></a>Jetty Jspc Maven Plugin</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="jetty-jspc-maven-plugin.html#jspc-config">Configuration</a></span></dt><dt><span class="section"><a href="jetty-jspc-maven-plugin.html#jspc-production-precompile">Precompiling only for Production Build</a></span></dt><dt><span class="section"><a href="jetty-jspc-maven-plugin.html#jspc-overlay-precompile">Precompiling Jsps with Overlaid Wars</a></span></dt></dl></div><p>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.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jspc-config"></a>Configuration</h3></div></div></div><p>Here's the basic setup required to put the jspc plugin into your
build:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jspc-maven-plugin</artifactId>
<version>9.3.0.v20150612</version>
<executions>
<execution>
<id>jspc</id>
<goals>
<goal>jspc</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
]]>
</script></div><p>The configurable parameters are as follows:</p><div class="variablelist"><dl><dt><span class="term">webXmlFragment</span></dt><dd><p>Default value: ${project.basedir}/target/webfrag.xml</p><p>File into which to generate the servlet declarations. Will be
merged with an existing web.xml.</p></dd><dt><span class="term">webAppSourceDirectory</span></dt><dd><p>Default value: ${project.basedir}/src/main/webapp</p><p>Root of resources directory where jsps, tags etc are
located.</p></dd><dt><span class="term">webXml</span></dt><dd><p>Default value:
${project.basedir}/src/main/webapp/WEB-INF/web.xml</p><p>The web.xml file to use to merge with the generated
fragments.</p></dd><dt><span class="term">includes</span></dt><dd><p>Default value: **\/*.jsp, **\/*.jspx</p><p>The comma separated list of patterns for file extensions to be
processed.</p></dd><dt><span class="term">excludes</span></dt><dd><p>Default value: **\/.svn\/**</p><p>The comma separated list of patterns for file extensions to be
skipped.</p></dd><dt><span class="term">classesDirectory</span></dt><dd><p>Default value: ${project.build.outputDirectory}</p><p>Location of classes for the webapp.</p></dd><dt><span class="term">generatedClasses</span></dt><dd><p>Default value: ${project.build.outputDirectory}</p><p>Location to put the generated classes for the jsps.</p></dd><dt><span class="term">insertionMarker</span></dt><dd><p>Default value: <span class="emphasis"><em>none</em></span></p><p>A marker string in the src web.xml file which indicates where
to merge in the generated web.xml fragment. Note that the marker
string will NOT be preserved during the insertion. Can be left
blank, in which case the generated fragment is inserted just before
the line containing &lt;/web-app&gt;.</p></dd><dt><span class="term">useProvidedScope</span></dt><dd><p>Default value: false</p><p>If true, jars of dependencies marked with
&lt;scope&gt;provided&lt;/scope&gt; will be placed on the
compilation classpath.</p></dd><dt><span class="term">mergeFragment</span></dt><dd><p>Default value: true</p><p>Whether or not to merge the generated fragment file with the
source web.xml. The merged file will go into the same directory as
the webXmlFragment.</p></dd><dt><span class="term">keepSources</span></dt><dd><p>Default value: false</p><p>If true, the generated .java files are not deleted at the end
of processing.</p></dd><dt><span class="term">tldJarNamePatterns</span></dt><dd><p>Default value:
.*taglibs[^/]*\.jar|.*jstl-impl[^/]*\.jar$</p><p>Patterns of jars on the 'system' (ie container) path that
contain tlds. Use | to separate each pattern.</p></dd><dt><span class="term">jspc</span></dt><dd><p>Default value: the org.apache.jasper.JspC instance being
configured.</p><p>The JspC class actually performs the precompilation. All
setters on the JspC class are available. You can <a class="link" href="http://central.maven.org/maven2/org/glassfish/web/javax.servlet.jsp/2.3.2/javax.servlet.jsp-2.3.2-javadoc.jar" target="_top">download</a>
the <a class="link" href="">javadoc</a> <a class="link" href="http://central.maven.org/maven2/org/glassfish/web/javax.servlet.jsp/2.3.2/javax.servlet.jsp-2.3.2-javadoc.jar" target="_top">here</a>.</p></dd></dl></div><p>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:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${project.basedir}/target/web.xml</webXml>
</configuration>
</plugin>
]]>
</script></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jspc-production-precompile"></a>Precompiling only for Production Build</h3></div></div></div><p>As compiling jsps is usually done during preparation for a
production release and not usually done during development, it is more
convenient to put the plugin setup inside a &lt;profile&gt; which which
can be deliberately invoked during prep for production.</p><p>For example, the following profile will only be invoked if the flag
-Dprod is present on the run line:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[
<profiles>
<profile>
<id>prod</id>
<activation>
<property><name>prod</name></property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jspc-maven-plugin</artifactId>
<version>9.3.0.v20150612</version>
<!-- put your configuration in here -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<!-- put your configuration in here -->
</plugin>
</plugins>
</build>
</profile>
</profiles>
]]>
</script></div><p>So, the following invocation would cause your code to be compiled,
the jsps to be compiled, the &lt;servlet&gt; and &lt;servlet-mapping&gt;s
inserted in the web.xml and your webapp assembled into a war:</p><div class="screenexample"><pre class="screen">
$ mvn -Dprod package
</pre></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jspc-overlay-precompile"></a>Precompiling Jsps with Overlaid Wars</h3></div></div></div><p>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.</p><p>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.</p><p>Here's an example configuration of the war plugin that separate
those phases into an unpack phase, and then a packing phase:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[
<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>
]]>
</script></div><p>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.</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jspc-maven-plugin</artifactId>
<version>9.3.0.v20150612</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>
]]>
</script></div></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jetty-maven-scanning.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="maven-and-jetty.html"><i class="icon-chevron-up"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ant-and-jetty.html">Next <i class="icon-chevron-right"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Files Scanned by the Jetty Maven Plugin&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="icon-home"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Chapter&nbsp;22.&nbsp;Using Ant with Jetty</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/jetty-project/jetty-documentation">Contribute to this documentation at
<span class="website"><i class="icon-github"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2015-06-15T13:18:29-05:00)</i></span></div></p><script xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1149868-7']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></body></html>