blob: 9815f4c30c9c3f8e4716aeb5009395ec731bbbde [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 Stylesheets V1.79.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"><link rel="up" href="maven-and-jetty.html" title="Chapter&nbsp;23.&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;24.&nbsp;Ant and 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"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
hljs.initHighlightingOnLoad();
</script><link type="text/css" rel="stylesheet" href="css/font-awesome/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.4.28-SNAPSHOT</span></td><td style="width: 50%"></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="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;23.&nbsp;Maven and Jetty<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ant-and-jetty.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></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 for sponsored feature development
</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 class="toc"><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&#8217;s the basic setup required to put the jspc plugin into your build:</p><pre 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"><code>&lt;plugin&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;jetty-jspc-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;9.4.28-SNAPSHOT&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;jspc&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;jspc&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;</code></pre><p>The configurable parameters are as follows:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">webXmlFragment</span></dt><dd><p class="simpara">Default value: <code class="literal">$\{project.basedir}/target/webfrag.xml</code></p><p class="simpara">File into which to generate the servlet declarations.
Will be merged with an existing <code class="literal">web.xml</code>.</p></dd><dt><span class="term">webAppSourceDirectory</span></dt><dd><p class="simpara">Default value: <code class="literal">$\{project.basedir}/src/main/webapp</code></p><p class="simpara">Root of resources directory where jsps, tags etc are located.</p></dd><dt><span class="term">webXml</span></dt><dd><p class="simpara">Default value: <code class="literal">$\{project.basedir}/src/main/webapp/WEB-INF/web.xml</code></p><p class="simpara">The web.xml file to use to merge with the generated fragments.</p></dd><dt><span class="term">includes</span></dt><dd><p class="simpara">Default value: <code class="literal">**\/*.jsp, **\/*.jspx</code></p><p class="simpara">The comma separated list of patterns for file extensions to be processed.</p></dd><dt><span class="term">excludes</span></dt><dd><p class="simpara">Default value: <code class="literal">**\/.svn\/**</code></p><p class="simpara">The comma separated list of patterns for file extensions to be skipped.</p></dd><dt><span class="term">classesDirectory</span></dt><dd><p class="simpara">Default value: <code class="literal">$\{project.build.outputDirectory}</code></p><p class="simpara">Location of classes for the webapp.</p></dd><dt><span class="term">generatedClasses</span></dt><dd><p class="simpara">Default value: <code class="literal">$\{project.build.outputDirectory}</code></p><p class="simpara">Location to put the generated classes for the jsps.</p></dd><dt><span class="term">insertionMarker</span></dt><dd><p class="simpara">Default value: <span class="emphasis"><em>none</em></span></p><p class="simpara">A marker string in the src <code class="literal">web.xml</code> 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 <code class="literal">&lt;/web-app&gt;</code>.</p></dd><dt><span class="term">useProvidedScope</span></dt><dd><p class="simpara">Default value: false</p><p class="simpara">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 class="simpara">Default value: true</p><p class="simpara">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 class="simpara">Default value: false</p><p class="simpara">If true, the generated .java files are not deleted at the end of processing.</p></dd><dt><span class="term">sourceVersion</span></dt><dd>Introduced in Jetty 9.3.6.
Java version of jsp source files.
Defaults to 1.7.</dd><dt><span class="term">targetVersion</span></dt><dd>Introduced in Jetty 9.3.6.
Java version of class files generated from jsps.
Defaults to 1.7.</dd><dt><span class="term">tldJarNamePatterns</span></dt><dd><p class="simpara">Default value: <code class="literal">.*taglibs[^/]*\.jar|.*jstl-impl[^/]*\.jar$</code></p><p class="simpara">Patterns of jars on the <span class="emphasis"><em>system</em></span> (ie container) path that contain tlds.
Use | to separate each pattern.</p></dd><dt><span class="term">jspc</span></dt><dd><p class="simpara">Default value: the <code class="literal">org.apache.jasper.JspC</code> instance being configured.</p><p class="simpara">The JspC class actually performs the pre-compilation.
All setters on the JspC class are available.
You can download the javadoc <a class="link" href="https://repo1.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&#8217;s how to configure the war plugin to use the generated <code class="literal">web.xml</code> that includes all of the jsp servlet declarations:</p><pre 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"><code>&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;webXml&gt;${project.basedir}/target/web.xml&lt;/webXml&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;</code></pre></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 <code class="literal">-Dprod</code> is present on the run line:</p><pre 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"><code>&lt;profiles&gt;
&lt;profile&gt;
&lt;id&gt;prod&lt;/id&gt;
&lt;activation&gt;
&lt;property&gt;&lt;name&gt;prod&lt;/name&gt;&lt;/property&gt;
&lt;/activation&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;jetty-jspc-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;9.4.28-SNAPSHOT&lt;/version&gt;
&lt;!-- put your configuration in here --&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
&lt;!-- put your configuration in here --&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/profile&gt;
&lt;/profiles&gt;</code></pre><p>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 <code class="literal">web.xml</code> 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&#8217;ll show, we will use an overlaid war.
The overlaid war will provide the <code class="literal">web.xml</code> file but the jsps will be in <code class="literal">src/main/webapp</code> (i.e. 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 <code class="literal">web.xml</code>, then pack everything into a war.</p><p>Here&#8217;s an example configuration of the war plugin that separate those phases into an unpack phase, and then a packing phase:</p><pre 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"><code>&lt;plugin&gt;
&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;unpack&lt;/id&gt;
&lt;goals&gt;&lt;goal&gt;exploded&lt;/goal&gt;&lt;/goals&gt;
&lt;phase&gt;generate-resources&lt;/phase&gt;
&lt;configuration&gt;
&lt;webappDirectory&gt;target/foo&lt;/webappDirectory&gt;
&lt;overlays&gt;
&lt;overlay /&gt;
&lt;overlay&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;test-jetty-webapp&lt;/artifactId&gt;
&lt;/overlay&gt;
&lt;/overlays&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;id&gt;pack&lt;/id&gt;
&lt;goals&gt;&lt;goal&gt;war&lt;/goal&gt;&lt;/goals&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;configuration&gt;
&lt;warSourceDirectory&gt;target/foo&lt;/warSourceDirectory&gt;
&lt;webXml&gt;target/web.xml&lt;/webXml&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;</code></pre><p>Now you also need to configure the <code class="literal">jetty-jspc-maven-plugin</code> 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 <code class="literal">target/foo/WEB-INF/web.xml</code>.
Using the default settings, the <code class="literal">web.xml</code> merged with the jsp servlet definitions will be put into <code class="literal">target/web.xml</code>.</p><pre 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"><code>&lt;plugin&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;jetty-jspc-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;9.4.28-SNAPSHOT&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;jspc&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;jspc&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;webXml&gt;target/foo/WEB-INF/web.xml&lt;/webXml&gt;
&lt;includes&gt;**/*.foo&lt;/includes&gt;
&lt;excludes&gt;**/*.fff&lt;/excludes&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;</code></pre></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="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="maven-and-jetty.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ant-and-jetty.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></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="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Chapter&nbsp;24.&nbsp;Ant and 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/eclipse/jetty.project">Contribute to this documentation at
<span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2020-03-10)</i></span></div></p></body></html>