blob: be28dfba1ed9a4e70b7bc4234addacbdaac0838a [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-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="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"><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">Temporary Directories</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="configuring-virtual-hosts.html"><i class="icon-chevron-left"></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="icon-home"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="serving-webapp-from-particular-port.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="ref-temporary-directories"></a>Temporary Directories</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ref-temporary-directories.html#d0e3729">The default temp directory</a></span></dt><dt><span class="section"><a href="ref-temporary-directories.html#d0e3789">Setting a specific temp directory</a></span></dt><dt><span class="section"><a href="ref-temporary-directories.html#d0e3832">The "work" directory</a></span></dt><dt><span class="section"><a href="ref-temporary-directories.html#d0e3839">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="d0e3729"></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><div class="screenexample"><pre class="screen">"jetty-"+host+"-"+port+"-"+resourceBase+"-_"+context+"-"+virtualhost+"-"+randomdigits+".dir"</pre></div><p>For example:</p><div class="screenexample"><pre class="screen">jetty-0.0.0.0-8080-test.war-_test-any-8900275691885214790.dir</pre></div><p>Where <code class="code">0.0.0.0</code> is the host address, <code class="code">8080</code> is
the port, <code class="code">test.war</code> is the resourceBase, <code class="code">test</code> is
the context path (with / converted to _), <code class="code">any</code> is the virtual
host, and <code class="code">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="code">javax.servlet.context.tempdir.</code></p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="d0e3764"></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="code">java.io.tmpdir</code> System property. You can
instruct Jetty to use a different parent directory by setting the
context attribute <code class="code">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. Here's an example of setting
it in an xml file:</p><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/test</Set>
<Set name="war">foo.war</Set>
<Call name="setAttribute">
<Arg>org.eclipse.jetty.webapp.basetempdir</Arg>
<Arg>/home/my/foo</Arg>
</Call>
</Configure>
]]>
</script><p>The equivalent in code is:</p><script type="syntaxhighlighter" class="brush: java;toolbar: false">
<![CDATA[WebAppContext context = new WebAppContext();
context.setContextPath("/test");
context.setWar("foo.war");
context.setAttribute("org.eclipse.jetty.webapp.basetempdir", "/tmp/foo");]]>
</script></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e3789"></a>Setting a specific temp directory</h3></div></div></div><p>To use a particular directory as the temporary directory you can do
either:</p><div class="variablelist"><dl><dt><span class="term">call WebAppContext.setTempDirectory(String dir)</span></dt><dd><p>As usual with Jetty, you can do this with an xml file or
directly in code. Here's an example of setting the temp directory in
xml:</p><p><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/test</Set>
<Set name="war">foo.war</Set>
<Set name="tempDirectory">/some/dir/foo</Set>
</Configure>]]>
</script>Here's an example of doing it with java
code:</p><script type="syntaxhighlighter" class="brush: java;toolbar: false">
<![CDATA[WebAppContext context = new WebAppContext();
context.setContextPath("/test");
context.setWar("foo.war");
context.setTempDirectory(new File("/some/dir/foo"));]]>
</script></dd><dt><span class="term">set the <code class="filename">javax.servlet.context.tempdir</code>
context attribute</span></dt><dd><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><script type="syntaxhighlighter" class="brush: xml;toolbar: false">
<![CDATA[<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/test</Set>
<Set name="war">foo.war</Set>
<Call name="setAttribute">
<Arg>javax.servlet.context.tempdir</Arg>
<Arg>/some/dir/foo</Arg>
</Call>
</Configure>]]>
</script><p>Or in java:</p><script type="syntaxhighlighter" class="brush: java;toolbar: false">
<![CDATA[WebAppContext context = new WebAppContext();
context.setContextPath("/test");
context.setWar("foo.war");
context.setAttribute("javax.servlet.context.tempdir", "/some/dir/foo");]]>
</script></dd></dl></div><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="code">javax.servlet.context.tempdir</code> attribute of the web
application.</p><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="icon-asterisk"></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 caching of jar contents: <a class="link" href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4774421" target="_top">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4774421</a></p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e3832"></a>The "work" directory</h3></div></div></div><p>Mostly for backward compatibility, from jetty-9.1.1 onwards, it will
be possible to create a directory named "work" in the ${jetty.base}
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 that ${jetty.base}. Moreover, as has historically been the
case, these temp directories inside the work directory are not cleaned up
when jetty exists (or more correctly speaking, the temp dir 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 dirs omits the random digit string. This
ensures the name of the dir remains consistent across context
restarts.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e3839"></a>Persisting the temp directory</h3></div></div></div><p>Sometimes you may find it useful to keep the contents of the
temporary directory between restarts of the web application. By default,
Jetty will <span class="emphasis"><em>not</em></span> persist the temp directory. To cause
Jetty to keep it, use <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/webapp/WebAppContext.html" target="_top">WebAppContext.setPersistTempDirectory(true)</a>.</p><p>Be aware that if you call setPersistTempDirectory(true), but let
Jetty create a new temp directory each time (ie you do NOT set an explicit
temp directory), then you will accumulate temp directories in your chosen
temp directory 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="configuring-virtual-hosts.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="configuring-contexts.html"><i class="icon-chevron-up"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="serving-webapp-from-particular-port.html">Next <i class="icon-chevron-right"></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="icon-home"></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/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:15-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>