| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Quickstart Webapps</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="configuring-deployment.html" title="Chapter 4. Deploying to Jetty"><link rel="prev" href="deployment-architecture.html" title="Deployment Architecture"><link rel="next" href="configuring-contexts.html" title="Chapter 5. Configuring Contexts"><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">Quickstart Webapps</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="deployment-architecture.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><th width="60%" align="center">Chapter 4. Deploying to 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"> <a accesskey="n" href="configuring-contexts.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="quickstart-webapp"></a>Quickstart Webapps</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="quickstart-webapp.html#_setting_up_quickstart">Setting up Quickstart</a></span></dt><dt><span class="section"><a href="quickstart-webapp.html#_avoiding_tld_scans_with_precompiled_jsps">Avoiding TLD Scans with precompiled JSPs</a></span></dt><dt><span class="section"><a href="quickstart-webapp.html#_bypassing_start_jar">Bypassing start.jar</a></span></dt></dl></div><p>The auto discovery features of the Servlet specification can make deployments slow and uncertain. |
| Auto discovery of Web Application configuration can be useful during the development of a webapp as it allows new features and frameworks to be enabled simply by dropping in a jar file. |
| However, for deployment, the need to scan the contents of many jars can have a significant impact of the start time of a webapp.</p><p>With the release of Jetty 9.2, a quickstart module was included which allows a webapp to be pre-scanned and preconfigured. |
| This means that all the scanning is done prior to deployment and all configuration is encoded into an effective <code class="literal">web.xml</code>, called <code class="literal">WEB-INF/quickstart-web.xml</code>, which can be inspected to understand what will be deployed before deploying. |
| Not only does the <code class="literal">quickstart-web.xml</code> contain all the discovered Servlets, Filters and Constraints, but it also encodes as context parameters all discovered:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">ServletContainerInitializers</li><li class="listitem">HandlesTypes classes</li><li class="listitem">Taglib Descriptors</li></ul></div><p>With the quickstart mechanism, Jetty is able to entirely bypass all scanning and discovery modes and start a webapp in a predictable and fast way. |
| Tests have shown that webapps that took many seconds to scan and deploy can now be deployed in a few hundred milliseconds.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_setting_up_quickstart"></a>Setting up Quickstart</h3></div></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_prerequisites"></a>Prerequisites</h4></div></div></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="_jetty_distribution"></a>Jetty Distribution</h5></div></div></div><p>In a standard Jetty distribution the quickstart module can be configured with the following command:</p><div class="screenexample"><pre class="screen">$ java -jar $JETTY_HOME/start.jar --add-to-start=quickstart</pre></div></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="_embedded"></a>Embedded</h5></div></div></div><p>In a Maven project you add a dependency on the artifact <code class="literal">jetty-quickstart</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><dependency> |
| <groupId>org.eclipse.jetty</groupId> |
| <artifactId>jetty-quickstart</artifactId> |
| <version>9.4.28-SNAPSHOT</version> |
| </dependency></code></pre></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_configuration"></a>Configuration</h4></div></div></div><p>Webapps need to be instances of <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.4.28-SNAPSHOT/org/eclipse/jetty/quickstart/QuickStartWebApp.html" target="_top"><code class="literal">org.eclipse.jetty.quickstart.QuickStartWebApp</code></a> rather than the normal <code class="literal">org.eclipse.jetty.webapp.WebAppContext</code>.</p><p><code class="literal">org.eclipse.jetty.quickstart.QuickStartWebApp</code> instances offer the same setters as the familiar <code class="literal">org.eclipse.jetty.webapp.WebAppContext</code>, with the addition of:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">autoPreconfigure</span></dt><dd>(true/false). |
| If true, the first time the webapp is run, the WEB-INF/quickstart-web.xml is generated BEFORE the webapp is deployed. |
| Subsequent runs use the previously generated quickstart file.</dd><dt><span class="term">originAttribute</span></dt><dd>The name of an attribute to insert into the generated elements in quickstart-web.xml that gives the origin of the element. |
| By default it is <code class="literal">origin</code>.</dd><dt><span class="term">generateOrigin</span></dt><dd>(true/false). |
| By default it is <code class="literal">false</code>. |
| If true, the origin attribute will be inserted into each element in quickstart-web.xml. |
| Note that origin attributes will also be generated if debug log level is enabled.</dd></dl></div><div class="blockquote"><blockquote class="blockquote"><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="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="fa fa-asterisk" aria-hidden="true"></i> Note</h3><p>If you are using Spring-Boot you must set <code class="literal">generateOrigin</code> to true.</p></div></blockquote></div><p>The origin is either a descriptor eg web.xml,web-fragment.xml,override-web.xml file, or an annotation eg @WebServlet. |
| For xml validation each attribute must be unique, and therefore an integer counter is appended to each value. |
| Some examples of elements with origin attribute information are:</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><listener origin="DefaultsDescriptor(file:///path/to/distro/etc/webdefault.xml):21"> |
| <listener origin="WebDescriptor(file:///path/to/base/webapps/test-spec/WEB-INF/web.xml):22"> |
| <servlet-class origin="FragmentDescriptor(jar:file:///path/to/base/webapps/test-spec/WEB-INF/lib/test-web-fragment.jar!/META-INF/web-fragment.xml):23"> |
| <servlet-class origin="@WebServlet(com.acme.test.TestServlet):24"></code></pre><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="_in_xml"></a>In XML</h5></div></div></div><p>If a web application already has a context xml file, eg <code class="literal">webapps/myapp.xml</code> file, simply change the class in the <code class="literal">Configure</code> element. |
| Otherwise, create a context xml file with the following information (in addition to the usual setting of contextPath, war etc):</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><?xml version="1.0" encoding="UTF-8"?> |
| <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> |
| <Configure class="org.eclipse.jetty.quickstart.QuickStartWebApp"> |
| <Set name="autoPreconfigure">true</Set> |
| </Configure></code></pre></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="_in_code"></a>In Code</h5></div></div></div><p>Create an instance of <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.4.28-SNAPSHOT/org/eclipse/jetty/quickstart/QuickStartWebApp.html" target="_top"><code class="literal">org.eclipse.jetty.quickstart.QuickStartWebApp</code></a> rather than the normal <code class="literal">org.eclipse.jetty.webapp.WebAppContext</code>. You then use the QuickStartWebApp instance in exactly the same way that you would a WebAppContext.</p><p>Here’s a snippet:</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> QuickStartWebApp webapp = new QuickStartWebApp(); |
| webapp.setAutoPreconfigure(true);</code></pre></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="_pre_generating_the_quickstart_web_xml_file"></a>Pre-generating the quickstart-web.xml file</h5></div></div></div><p>Rather than use the <code class="literal">autoPreconfigure</code> feature of the QuickStartWebApp - which lazily generates the <code class="literal">quickstart-web.xml</code> file - you can eagerly pre-generate it for an existing war by invoking as a main class <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.4.28-SNAPSHOT/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.html" target="_top"><code class="literal">org.eclipse.jetty.quickstart.PreconfigureQuickStartWar</code></a>. |
| Note that you will need to provide all necessary jetty jars on the command line classpath. |
| This will unpack the war if necessary, and create the <code class="literal">quickstart-web.xml</code> before the first deployment:</p><div class="screenexample"><pre class="screen">$ java -cp [jetty classpath] org.eclipse.jetty.quickstart.PreconfigureQuickStartWar myapp.war</pre></div><p>Run the class with no arguments to see other runtime options.</p><p>Alternatively, you could use the <a class="link" href="jetty-maven-plugin.html#get-up-and-running" title="Quick Start: Get Up and Running">Jetty Maven Plugin</a> goal <a class="link" href="jetty-maven-plugin.html#jetty-effective-web-xml" title="jetty:effective-web-xml"><code class="literal">jetty:effective-web-xml</code></a>: this will generate quickstart information, but print it to stderr. |
| The goal provides a configuration option to save the output to a file, which you can then copy into your webapp’s WEB-INF dir. |
| Note that as the Jetty Maven Plugin is a general tool for running webapps, it may have more jars on its classpath than are needed by your application, and thus may generate extra quickstart information: we recommend that you use this goal only as a quick guide to the type of information that quickstart generates.</p></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_avoiding_tld_scans_with_precompiled_jsps"></a>Avoiding TLD Scans with precompiled JSPs</h3></div></div></div><p>Of course precompiling JSPs is an excellent way to improve the start time of a web application. |
| As of Jetty 9.2 the Apache Jasper JSP implementation has been used and has been augmented to allow the TLD scan to be skipped. |
| This can be done by adding a <code class="literal">context-param</code> to the <code class="literal">web.xml</code> file (this is done automatically by the Jetty Maven JSPC plugin):</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><context-param> |
| <param-name>org.eclipse.jetty.jsp.precompiled</param-name> |
| <param-value>true</param-value> |
| </context-param></code></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_bypassing_start_jar"></a>Bypassing start.jar</h3></div></div></div><p>The Jetty <code class="literal">start.jar</code> mechanism is a very powerful and flexible mechanism for constructing a <code class="literal">classpath</code> and executing a configuration encoded in Jetty XML format. |
| However, this mechanism does take some time to build the <code class="literal">classpath</code>. |
| The start.jar mechanism can be bypassed by using the <code class="literal">–dry-run</code> option to generate and reuse a complete command line to start Jetty at a later time:</p><div class="screenexample"><pre class="screen">$ RUN=$(java -jar $JETTY_HOME/start.jar --dry-run) |
| $ eval $RUN</pre></div><p>Note that <code class="literal">--dry-run</code> may create a properties file in the temp directory and include it on the generated command line. |
| If so, then a copy of the temporary properties file should be taken and the command line updated with it’s new persistent location.</p></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="deployment-architecture.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><td width="20%" align="center"><a accesskey="u" href="configuring-deployment.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right"> <a accesskey="n" href="configuring-contexts.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Deployment Architecture </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"> Chapter 5. Configuring Contexts</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> |