6 Feb 2009

Jetty - change default java.io.tmpdir value and override web.xml parameters

Jetty is really nice, amongst the amazing things you can do some of my favorites are:
  • Change java.io.tmpdir default value
  • override params define in the web.xml embedded in a war file


java.io.tmpdir


<?xml version="1.0"  encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="contextPath">/test</Set>
...
<!-- change java.io.tmpdir default value -->
<Call class="java.lang.System" name="setProperty">
<Arg>java.io.tmpdir</Arg>
<Arg>/some/where</Arg>
</Call>
</Configure>

Change default values in web.xml


<?xml version="1.0"  encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="contextPath">/test</Set>
...
<Set name="overrideDescriptor">
<SystemProperty name="jetty.home"
default="."/>/contexts/test.d/override-web.xml</Set>
</Configure>

Create an 'override-web.xml'
<?xml version="1.0"  encoding="UTF-8"?>
<web-app ...>
<!-- Add or override context init parameter -->
<context-param>
<param-name>my.param/param-name>
<param-value>on</param-value>
</context-param>
</web-app>

6 comments:

Anonymous said...

The web.xml override feature originates from Joost: an idea of mine, written by Torsten and contributed back by Pier :-)

Benjamin Francisoud said...

I knew it was heavily used at Joost.
I knew Pier contributed to Jetty.
But I didn't know it was your idea ;)
Well done :)

Int64 said...

It would be great to have a little bit more descriptive override-web.xml file

Anonymous said...

Nice hint, thank you :)
We at jvmhost.com also use TMPDIR environment variable to set the directory Jetty wide.

Unknown said...

I need to override a filter mapping on the original web.xml.. that can be done with this override feature ?

Benjamin Francisoud said...

Supposedly yes ;)