blob: 845c9380f8a6399a7d629957e4c5609cb206b459 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter&nbsp;19.&nbsp;Jetty Runner</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="jetty-admin-guide.html" title="Part&nbsp;III.&nbsp;Jetty Administration Guide"><link rel="prev" href="rewrite-handler.html" title="Rewrite Handler"><link rel="next" href="optimizing.html" title="Chapter&nbsp;20.&nbsp;Optimizing 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.3.28.v20191105</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">Chapter&nbsp;19.&nbsp;Jetty Runner</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="rewrite-handler.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;III.&nbsp;Jetty Administration Guide<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="optimizing.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="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="runner"></a>Chapter&nbsp;19.&nbsp;Jetty Runner</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="runner.html#jetty-runner">Use Jetty without an installed distribution</a></span></dt></dl></div><p>This chapter explains how to use the <code class="literal">jetty-runner</code> to run your webapps without needing an installation of Jetty.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="jetty-runner"></a>Use Jetty without an installed distribution</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="runner.html#jetty-runner-preparation">Preparation</a></span></dt><dt><span class="section"><a href="runner.html#_deploying_a_simple_context">Deploying a simple context</a></span></dt><dt><span class="section"><a href="runner.html#_deploying_multiple_contexts">Deploying multiple contexts</a></span></dt></dl></div><p>The idea of the <code class="literal">jetty-runner</code> is extremely simple &#8211; run a webapp directly from the command line using a single jar file and as much default configuration as possible.
Of course, if your webapp is not so straightforward, the <code class="literal">jetty-runner</code> has command line options which allow you to customize the execution environment.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jetty-runner-preparation"></a>Preparation</h3></div></div></div><p>You will need the <code class="literal">jetty-runner</code> jar:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><a class="link" href="http://central.maven.org/maven2/org/eclipse/jetty/jetty-runner/" target="_top">Get</a> the <code class="literal">jetty-runner</code> jar available at <a class="link" href="http://search.maven.org/#browse" target="_top">maven central</a>.</li></ol></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_deploying_a_simple_context"></a>Deploying a simple context</h3></div></div></div><p>Let&#8217;s assume we have a very simple webapp that does not need any resources from its environment, nor any configuration apart from the defaults.
Starting it is as simple as performing the following:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar simple.war</pre></div><p>This will start Jetty on port 8080, and deploy the webapp to <code class="literal">/</code>.</p><p>Your webapp does not have to be packed into a war, you can deploy a webapp that is a directory instead in the same way:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar simple</pre></div><p>In fact, the webapp does not have to be a war or even a directory, it can simply be a Jetty context xml file that describes your webapp:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar simple-context.xml</pre></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>When using a context xml file, the application being deployed is not even required to be a fully-fledged webapp. It can simply be a Jetty <a class="link" href="architecture.html#what-is-a-context" title="Contexts">context</a>.</p></div></blockquote></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_deploying_multiple_contexts"></a>Deploying multiple contexts</h3></div></div></div><p>If you have more than one webapp that must be deployed, simply provide them all on the command line.
You can control the context paths for them using the <code class="literal">--path</code> parameter.
Here&#8217;s an example of deploying 2 wars (although either or both of them could be unpacked directories instead):</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --path /one my1.war --path /two my2.war</pre></div><p>If you have context xml files that describe your webapps, you can fully configure your webapps in them and hence you don&#8217;t need to use the command line switches.
Just provide the list of context files like so:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar my-first-context.xml my-second-context.xml my-third-context.xml</pre></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>Switched used on the command line override configuration file settings.
So, for example, you could set the context path for the webapp inside the context xml file, and use the <code class="literal">--path</code> switch to override it on the command line.</p></div></blockquote></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_changing_the_default_port"></a>Changing the default port</h4></div></div></div><p>By default the <code class="literal">jetty-runner</code> will listen on port 8080.
You can easily change this on the command line using the <code class="literal">--port</code> command.
Here&#8217;s an example that runs our simple.war on port 9090:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --port 9090 simple.war</pre></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_using_jetty_xml_files"></a>Using jetty.xml files</h4></div></div></div><p>Instead of, or in addition to, using command line switches, you can use one or more <code class="literal">jetty.xml</code> files to configure the environment for your webapps.
Here&#8217;s an example where we apply two different <code class="literal">jetty.xml</code> files:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --config jetty.xml --config jetty-https.xml simple.war</pre></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_full_configuration_reference"></a>Full configuration reference</h4></div></div></div><p>You can see the fill set of configuration options using the <code class="literal">--help</code> switch:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --help</pre></div><p>Here&#8217;s what the output will look like:</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>Usage: java [-Djetty.home=dir] -jar jetty-runner.jar [--help|--version] [ server opts] [[ context opts] context ...]
Server opts:
--version - display version and exit
--log file - request log filename (with optional 'yyyy_mm_dd' wildcard
--out file - info/warn/debug log filename (with optional 'yyyy_mm_dd' wildcard
--host name|ip - interface to listen on (default is all interfaces)
--port n - port to listen on (default 8080)
--stop-port n - port to listen for stop command
--stop-key n - security string for stop command (required if --stop-port is present)
[--jar file]*n - each tuple specifies an extra jar to be added to the classloader
[--lib dir]*n - each tuple specifies an extra directory of jars to be added to the classloader
[--classes dir]*n - each tuple specifies an extra directory of classes to be added to the classloader
--stats [unsecure|realm.properties] - enable stats gathering servlet context
[--config file]*n - each tuple specifies the name of a jetty xml config file to apply (in the order defined)
Context opts:
[[--path /path] context]*n - WAR file, web app dir or context xml file, optionally with a context path</code></pre><div class="variablelist"><dl class="variablelist"><dt><span class="term">Printing the version</span></dt><dd><p class="simpara">Print out the version of Jetty and then exit immediately.</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --version</pre></div></dd><dt><span class="term">Configuring a request log</span></dt><dd><p class="simpara">Cause Jetty to write a request log with the given name.
If the file is prefixed with <code class="literal">yyyy_mm_dd</code> then the file will be automatically rolled over.
Note that for finer grained configuration of the <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.3.28.v20191105/org/eclipse/jetty/server/NCSARequestLog.html" target="_top">request log</a>, you will need to use a Jetty xml file instead.</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --log yyyy_mm_dd-requests.log my.war</pre></div></dd><dt><span class="term">Configuring the output log</span></dt><dd><p class="simpara">Redirect the output of jetty logging to the named file.
If the file is prefixed with <code class="literal">yyyy_mm_dd</code> then the file will be automatically rolled over.</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --out yyyy_mm_dd-output.log my.war</pre></div></dd><dt><span class="term">Configuring the interface for http</span></dt><dd><p class="simpara">Like Jetty standalone, the default is for the connectors to listen on all interfaces on a machine.
You can control that by specifying the name or ip address of the particular interface you wish to use with the <code class="literal">--host</code> argument:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --host 192.168.22.19 my.war</pre></div></dd><dt><span class="term">Configuring the port for http</span></dt><dd><p class="simpara">The default port number is 8080.
To configure a https connector, use a Jetty xml config file instead.</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --port 9090 my.war</pre></div></dd><dt><span class="term">Configuring stop</span></dt><dd><p class="simpara">You can configure a port number for jetty to listen on for a stop command, so you are able to stop it from a different terminal.
This requires the use of a "secret" key, to prevent malicious or accidental termination.
Use the <code class="literal">--stop-port</code> and <code class="literal">--stop-key</code> parameters as arguments to the <code class="literal">jetty-runner</code>:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --stop-port 8181 --stop-key abc123</pre></div><p class="simpara">Then, to stop Jetty from a different terminal, you need to supply the same port and key information.
For this you&#8217;ll either need a local installation of Jetty, the <a class="link" href="jetty-maven-plugin.html" title="Configuring the Jetty Maven Plugin">jetty-maven-plugin</a>, the <a class="link" href="ant-and-jetty.html#jetty-ant" title="Ant Jetty Plugin">jetty-ant plugin</a>, or a custom class.
Here&#8217;s how to use a Jetty installation to perform a stop:</p><div class="screenexample"><pre class="screen">&gt; java -jar start.jar --stop-port 8181 --stop-key abc123 --stop</pre></div></dd><dt><span class="term">Configuring the container classpath</span></dt><dd><p class="simpara">With a local installation of Jetty, you add jars and classes to the container&#8217;s classpath by putting them in the <code class="literal">{$jetty.base}/lib</code> directory.
With the <code class="literal">jetty-runner</code>, you can use the <code class="literal">--lib</code>, <code class="literal">--jar</code> and <code class="literal">--classes</code> arguments instead to achieve the same thing.</p><p class="simpara"><code class="literal">--lib</code> adds the location of a directory which contains jars to add to the container classpath.
You can add 1 or more.
Here&#8217;s an example of configuring 2 directories:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --lib /usr/local/external/lib --lib $HOME/external-other/lib my.war</pre></div><p class="simpara"><code class="literal">--jar</code> adds a single jar file to the container classpath.
You can add 1 or more.
Here&#8217;s an example of configuring 3 extra jars:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --jar /opt/stuff/jars/jar1.jar --jar $HOME/jars/jar2.jar --jar /usr/local/proj/jars/jar3.jar my.war</pre></div><p class="simpara"><code class="literal">--classes</code> add the location of a directory containing classes to add to the container classpath.
You can add 1 or more.
Here&#8217;s an example of configuring a single extra classes dir:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --classes /opt/stuff/classes my.war</pre></div></dd><dt><span class="term">Gathering statistics</span></dt><dd><p class="simpara">If statistics gathering is enabled, then they are viewable by surfing to the context <code class="literal">/stats</code>.
You may optionally protect access to that context with a password.
Here&#8217;s an example of enabling statistics, with no password protection:</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --stats unsecure my.war</pre></div><p class="simpara">If we wished to protect access to the <code class="literal">/stats</code> context, we would provide the location of a Jetty realm configuration file containing authentication and authorization information.
For example, we could use the following example realm file from the Jetty distribution:</p><div class="screenexample"><pre class="screen">jetty: MD5:164c88b302622e17050af52c89945d44,user
admin: CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin
other: OBF:1xmk1w261u9r1w1c1xmq,user
plain: plain,user
user: password,user
# This entry is for digest auth. The credential is a MD5 hash of username:realmname:password
digest: MD5:6e120743ad67abfbc385bc2bb754e297,user</pre></div><p class="simpara">Assuming we&#8217;ve copied it into the local directory, we would apply it like so</p><div class="screenexample"><pre class="screen">&gt; java -jar jetty-runner.jar --stats realm.properties my.war</pre></div><p class="simpara">After navigating to <a class="link" href="http://localhost:8080/" target="_top">http://localhost:8080/</a> a few times, we can point to the stats servlet on <a class="link" href="http://localhost:8080/stats" target="_top">http://localhost:8080/stats</a> to see the output:</p><pre class="literallayout">Statistics:
Statistics gathering started 1490627ms ago
Requests:
Total requests: 9
Active requests: 1
Max active requests: 1
Total requests time: 63
Mean request time: 7.875
Max request time: 26
Request time standard deviation: 8.349764752888037
Dispatches:
Total dispatched: 9
Active dispatched: 1
Max active dispatched: 1
Total dispatched time: 63
Mean dispatched time: 7.875
Max dispatched time: 26
Dispatched time standard deviation: 8.349764752888037
Total requests suspended: 0
Total requests expired: 0
Total requests resumed: 0
Responses:
1xx responses: 0
2xx responses: 7
3xx responses: 1
4xx responses: 0
5xx responses: 0
Bytes sent total: 1453
Connections:
org.eclipse.jetty.server.ServerConnector@203822411
Protocols:http/1.1
Statistics gathering started 1490606ms ago
Total connections: 7
Current connections open: 1
Max concurrent connections open: 2
Total connections duration: 72883
Mean connection duration: 12147.166666666666
Max connection duration: 65591
Connection duration standard deviation: 23912.40292977684
Total messages in: 7
Total messages out: 7
Memory:
Heap memory usage: 49194840 bytes
Non-heap memory usage: 12611696 bytes</pre></dd></dl></div></div></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="rewrite-handler.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="jetty-admin-guide.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="optimizing.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Rewrite Handler&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;20.&nbsp;Optimizing 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: 2019-11-05)</i></span></div></p></body></html>