blob: 53c4f1b29031767c3e0203798fdec69418805be8 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Temporary Directories</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-contexts.html" title="Chapter&nbsp;5.&nbsp;Configuring Contexts"><link rel="prev" href="configuring-virtual-hosts.html" title="Configuring Virtual Hosts"><link rel="next" href="serving-webapp-from-particular-port.html" title="Serving a WebApp from a Particular Port/Connector"><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">Temporary Directories</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="configuring-virtual-hosts.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;5.&nbsp;Configuring Contexts<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="serving-webapp-from-particular-port.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="ref-temporary-directories"></a>Temporary Directories</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="ref-temporary-directories.html#_the_default_temp_directory">The default temp directory</a></span></dt><dt><span class="section"><a href="ref-temporary-directories.html#_setting_a_specific_temp_directory">Setting a specific temp directory</a></span></dt><dt><span class="section"><a href="ref-temporary-directories.html#_the_work_directory">The "work" directory</a></span></dt><dt><span class="section"><a href="ref-temporary-directories.html#_persisting_the_temp_directory">Persisting the temp directory</a></span></dt></dl></div><p>Jetty itself has no temporary directories, but you can assign a directory for each web application, into which the WAR is unpacked, JSPs compiled on-the-fly, etc.
If you do not assign a specific temporary directory, Jetty will create one as needed when your web application starts.
Whether you set the location of the temporary directory - or you let Jetty create one for you - you also have a choice to either keep or delete the temporary directory when the web application stops.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_the_default_temp_directory"></a>The default temp directory</h3></div></div></div><p>By default, Jetty will create a temporary directory for each web application. The name of the directory will be of the form:</p><pre class="literallayout">"jetty-"+host+"-"+port+"-"+resourceBase+"-_"+context+"-"+virtualhost+"-"+randomdigits+".dir"</pre><p>For example:</p><pre class="literallayout">jetty-0.0.0.0-8080-test.war-_test-any-8900275691885214790.dir</pre><p>Where <code class="literal">0.0.0.0</code> is the host address, <code class="literal">8080</code> is the port, <code class="literal">test.war</code> is the resourceBase, <code class="literal">test</code> is the context path (with / converted to _), <code class="literal">any</code> is the virtual host, and <code class="literal">randomdigits</code> are a string of digits guaranteed to be unique.</p><p>Once the temp directory is created, it is retrievable as the value (as a File) of the context attribute <code class="literal">javax.servlet.context.tempdir.</code></p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_the_location_of_the_temp_directory"></a>The location of the temp directory</h4></div></div></div><p>By default, Jetty will create this directory inside the directory named by the <code class="literal">java.io.tmpdir</code> System property.
You can instruct Jetty to use a different parent directory by setting the context attribute <code class="literal">org.eclipse.jetty.webapp.basetempdir</code> to the name of the desired parent directory.
The directory named by this attribute <span class="emphasis"><em>must</em></span> exist and be <span class="emphasis"><em>writeable</em></span>.</p><p>As usual with Jetty, you can either set this attribute in a context xml file, or you can do it in code.</p><p>Here&#8217;s an example of setting it in an xml file:</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;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/test&lt;/Set&gt;
&lt;Set name="war"&gt;foo.war&lt;/Set&gt;
&lt;Call name="setAttribute"&gt;
&lt;Arg&gt;org.eclipse.jetty.webapp.basetempdir&lt;/Arg&gt;
&lt;Arg&gt;/home/my/foo&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Configure&gt;</code></pre><p>The equivalent in code is:</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>WebAppContext context = new WebAppContext();
context.setContextPath("/test");
context.setWar("foo.war");
context.setAttribute("org.eclipse.jetty.webapp.basetempdir", "/tmp/foo");</code></pre></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_setting_a_specific_temp_directory"></a>Setting a specific temp directory</h3></div></div></div><p>There are several ways to use a particular directory as the temporary directory:</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_call_webappcontext_settempdirectory_string_dir"></a>Call WebAppContext.setTempDirectory(String dir)</h4></div></div></div><p>As before this can be accomplished with an xml file or directly in code. Here&#8217;s an example of setting the temp directory in xml:</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;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/test&lt;/Set&gt;
&lt;Set name="war"&gt;foo.war&lt;/Set&gt;
&lt;Set name="tempDirectory"&gt;/some/dir/foo&lt;/Set&gt;
&lt;/Configure&gt;</code></pre><p>Here&#8217;s an example of doing it with java 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>WebAppContext context = new WebAppContext();
context.setContextPath("/test");
context.setWar("foo.war");
context.setTempDirectory(new File("/some/dir/foo"));</code></pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_set_the_javax_servlet_context_tempdir_context_attribute"></a>Set the javax.servlet.context.tempdir context attribute</h4></div></div></div><p>You should set this context attribute with the name of directory you want to use as the temp directory. Again, you can do this in xml:</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;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/test&lt;/Set&gt;
&lt;Set name="war"&gt;foo.war&lt;/Set&gt;
&lt;Call name="setAttribute"&gt;
&lt;Arg&gt;javax.servlet.context.tempdir&lt;/Arg&gt;
&lt;Arg&gt;/some/dir/foo&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Configure&gt;</code></pre><p>Or in java:</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>WebAppContext context = new WebAppContext();
context.setContextPath("/test");
context.setWar("foo.war");
context.setAttribute("javax.servlet.context.tempdir", "/some/dir/foo");</code></pre><p>Once a temporary directory has been created by either of these methods, a file instance for it is set as the value of the <code class="literal">javax.servlet.context.tempdir</code> attribute of the web application.</p><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>Be wary of setting an explicit temp directory if you are likely to change the jars in WEB-INF/lib between redeployments.
There is a JVM bug concerning <a class="link" href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4774421" target="_top">caching of jar contents.</a></p></div></blockquote></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_the_work_directory"></a>The "work" directory</h3></div></div></div><p>Mostly for backward compatibility, from Jetty 9.1.1 onwards, it is possible to create a directory named "work" in the <code class="literal">$\{jetty.base}</code> directory.
If such a directory is found, it is assumed you want to use it as the parent directory for all of the temporary directories of the webapps in <code class="literal">$\{jetty.base}</code>.
Moreover, as has historically been the case, these temp directories inside the work directory are not cleaned up when Jetty exits (or more correctly speaking, the <code class="literal">temp</code> directory corresponding to a context is not cleaned up when that context stops).</p><p>When a work directory is used, the algorithm for generating the name of the context-specific temp directories omits the random digit string.
This ensures the name of the directory remains consistent across context restarts.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_persisting_the_temp_directory"></a>Persisting the temp directory</h3></div></div></div><p>Sometimes it is useful to keep the contents of the temporary directory between restarts of the web application.
By default, Jetty will <span class="strong"><strong>not</strong></span> persist the temp directory.
To configure Jetty to keep it, use <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.3.28.v20191105/org/eclipse/jetty/webapp/WebAppContext.html" target="_top">WebAppContext.setPersistTempDirectory(true)</a>.</p><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>Be aware that if you call <code class="literal">setPersistTempDirectory(true)</code>, but let Jetty create a new temp directory each time (i.e. you do NOT set an explicit temp directory), then you will accumulate temp directories in your chosen temp directory location.</p></div></blockquote></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="configuring-virtual-hosts.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="configuring-contexts.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="serving-webapp-from-particular-port.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Configuring Virtual Hosts&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;Serving a WebApp from a Particular Port/Connector</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>