Can't get jetty to read jetty-env.xml - jetty

I have the following:
Startup code:
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setDescriptor("/WEB-INF/web.xml");
context.setResourceBase("/home/webapp);
context.setContextPath("/");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
jetty-env.xml in /home/webapp/WEB-INF:
<?xml version="1.0"?>
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="properties" class="org.mortbay.jetty.plus.naming.EnvEntry">
<Arg>property_file</Arg>
<Arg>/home/webapp/web.properties</Arg>
</New>
</Configure>
jndi.properties in classpath:
java.naming.factory.url.pkgs=org.eclipse.jetty.jndi
java.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory
The initial context is created OK, but attempting to lookup the property_file key throws name not found exception. Enumeration only returns the keys defined in jndi.properties.
Context initContext = new InitialContext();
Hashtable<?,?> ht = initContext.getEnvironment();
Enumeration<?> keys = ht.keys();
while(keys.hasMoreElements()) {
Object key = keys.nextElement();
System.out.println(key.toString() + "=" + ht.get(key).toString());
}
String props=(String)initContext.lookup("java:comp/env/property_file");
What am I doing wrong?

You have a bad mix of jetty versions.
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="properties" class="org.mortbay.jetty.plus.naming.EnvEntry">
That points to Jetty 6 use, and ...
java.naming.factory.url.pkgs=org.eclipse.jetty.jndi
java.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory
points to Jetty 9 use...
This is what is messing you up.
The XML you are using will not work on Jetty 9 (Only Jetty 6), and the properties file you are defining should never be defined manually for Jetty 9 (its present in the jetty-jndi-{ver}.jar)
$ jar -tvf lib/jetty-jndi-9.2.9.v20150224.jar | grep jndi.properties
125 Tue Feb 24 10:49:42 MST 2015 jndi.properties
The instructions for Jetty 9 are found at
https://www.eclipse.org/jetty/documentation/current/jndi-embedded.html
This is how you setup Embedded Jetty with JNDI support.
There's some parts you need to enable in the WebAppContext configuration, and that should enable the jetty-env.xml to be used.
Namely ...
// Enable parsing of jndi-related parts of web.xml and jetty-env.xml
Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration",
"org.eclipse.jetty.plus.webapp.EnvConfiguration",
"org.eclipse.jetty.plus.webapp.PlusConfiguration");
Finally, the jetty-env.xml structure and syntax are documented here
https://www.eclipse.org/jetty/documentation/current/jndi-configuration.html
So your example would look like this ...
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="properties" class="org.eclipse.jetty.plus.jndi.EnvEntry">
<Arg><Ref refid="wac"/></Arg>
<Arg>property_file</Arg>
<Arg>/home/webapp/web.properties</Arg>
<Arg type="boolean">true</Arg>
</New>
</Configure>
Yes, the DOCTYPE is important.
As for the 4 parameters on EnvEntry, those are documented at the APIDOC site for EnvEntry.
One last piece of advice, DO NOT USE jetty-all.jar for your project, it exists only to allow some basic command line experimentation with Jetty, it is not meant to be used as a dependency in your project.

My apologies, I'm new to jetty and I forgot to mention that I was using embedded mode.
By now I've figured out that in the embedded mode jetty does NOT automatically read jetty-env.xml. You have to do it explicitly, for example:
Resource jettyEnv = Resource.newSystemResource("jetty-env.xml");
XmlConfiguration conf = new XmlConfiguration(jettyEnv.getInputStream());
Object obj = conf.configure();
WebAppContext context = (WebAppContext)obj;
The response about mixing different jetty versions does still apply.

Related

jetty static web content

I have tried a million different ways the last week to get jetty presenting a simple static html file. But it keeps giving me a 404 result.
The setup is:
Jetty is installed in: /usr/lib/jetty-home-11.0.2
The Jetty base dir: ~/Documents/projects/jetty/statWebApp/jetty_base
The module installed is http. (start.jar --add-module=http)
In ${jetty.base}/webapps are two files
index.html and web.xml
the web.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/</Set>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="resourceBase">/*</Set>
<Set name="directoriesListed">true</Set>
</New>
</Set>
</Configure>
The server is started with:
${jetty.base}/webapps java -jar /usr/lib/jetty-home-11.0.2/start.jar
I expect to see the index.html file when browsed to http://localhost:8080/.
I got 404 page presented by jetty. Therefor I know the server is started but it is not showing the page.
Any help on getting Jetty working will be very welcome.
I have added the deploy module(start.jar --add-module=http,deploy).
And I changed the path to the html file.
<Set name ="resourceBase">/home/edwin/Documents/projects/jetty/statWeb/jetty_base/webapps/</Set>
Or via the path relative
<Set name ="resourceBase">./webapps/</Set>
Both work.

Jetty warning "No resourceBase or war set for context" with Maven plugin

I use the jetty-maven-plugin with the following configuration:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.1.v20170120</version>
<configuration>
<jettyConfig>${basedir}/src/main/webapp/WEB-INF/development.jetty-config.xml</jettyConfig>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<contextPath>/</contextPath>
</contextHandler>
</contextHandlers>
<reload>manual</reload>
<scanIntervalSeconds>0</scanIntervalSeconds>
<webApp>
<contextPath>/</contextPath>
</webApp>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
</plugin>
The file development.jetty-config.xml has the following contents:
<?xml version="1.0"?>
<Configure class="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<Set name="resourceBase">./src/main/webapp</Set>
<Set name="contextPath">/</Set>
<Set name="war"><Property name="jetty.home" default="." />./src/main/webapp</Set>
<New id="proj1DS" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/proj1</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost/mydb</Set>
<Set name="User">root</Set>
<Set name="Password">***</Set>
<Set name="UseUnicode">true</Set>
<Set name="CharacterEncoding">UTF-8</Set>
</New>
</Arg>
</New>
</Configure>
I then start Jetty with a Maven command:
mvn jetty:run
Relevant plugin logs:
[INFO] <<< jetty-maven-plugin:9.4.1.v20170120:run (default-cli) < test-compile # proj1-admin <<<
[INFO]
[INFO] --- jetty-maven-plugin:9.4.1.v20170120:run (default-cli) # proj1-admin ---
2017-02-22 11:41:42.311:INFO::main: Logging initialized #3350ms to org.eclipse.jetty.util.log.StdErrLog
[INFO] Configuring Jetty for project: Proj Admin
[INFO] webAppSourceDirectory not set. Trying src/main/webapp
[INFO] Reload Mechanic: manual
[INFO] Classes = /home/igor/projects/Proj1/admin/target/classes
[INFO] Configuring Jetty from xml configuration file = /home/igor/projects/proj1/admin/src/main/webapp/WEB-INF/development.jetty-config.xml
[INFO] Context path = /
[INFO] Tmp directory = /home/igor/projects/proj1/admin/target/tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = file:///home/igor/projects/proj1/admin/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = /home/igor/projects/proj1/admin/src/main/webapp
2017-02-22 11:41:42.449:INFO:oejs.Server:main: jetty-9.4.1.v20170120
2017-02-22 11:41:44.694:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=1975ms
2017-02-22 11:41:44.904:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2017-02-22 11:41:44.904:INFO:oejs.session:main: No SessionScavenger set, using defaults
2017-02-22 11:41:44.907:INFO:oejs.session:main: Scavenging every 600000ms
Then it prints this warning:
2017-02-22 11:41:47.150:INFO:oejsh.ContextHandler:main: Started o.e.j.m.p.JettyWebAppContext#26e412ef{/,file:///home/igor/projects/proj1/admin/src/main/webapp/,AVAILABLE}{file:///home/igor/projects/proj1/admin/src/main/webapp/}
2017-02-22 11:41:47.154:WARN:oejw.WebInfConfiguration:main: Can't generate resourceBase as part of webapp tmp dir name: java.lang.IllegalStateException: No resourceBase or war set for context
2017-02-22 11:41:47.155:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.m.p.JettyWebAppContext#4ae263bf{/,null,null}
java.lang.IllegalStateException: No resourceBase or war set for context
at org.eclipse.jetty.webapp.WebInfConfiguration.unpack(WebInfConfiguration.java:406)
at org.eclipse.jetty.maven.plugin.MavenWebInfConfiguration.unpack(MavenWebInfConfiguration.java:135)
at org.eclipse.jetty.webapp.WebInfConfiguration.preConfigure(WebInfConfiguration.java:72)
at org.eclipse.jetty.maven.plugin.MavenWebInfConfiguration.preConfigure(MavenWebInfConfiguration.java:95)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:501)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:539)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:432)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:161)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.server.Server.start(Server.java:452)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:419)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:460)
at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:328)
at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute(JettyRunMojo.java:170)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
To my surprize, the application loads and workig properly. In addition, the three lines in the config file:
<Set name="resourceBase">./src/main/webapp</Set>
<Set name="contextPath">/</Set>
<Set name="war"><Property name="jetty.home" default="."/>./src/main/webapp</Set>
do not have any effect, even if I delete them.
I looked at the docs, and these answers, but cannot figure it out:
How to deploy my web application to jetty9 as root application?
No hot deployment in Jetty 9.0.6
Jetty config without resourceBase
My questions are:
How to properly configure this plugin to get rid of the warning?
Should I be really worried since this is not an ERROR and the app is working?
Your setup is confusing.
Why are you configuring org.eclipse.jetty.maven.plugin.JettyWebAppContext via a Jetty IoC Context XML directly? Don't do that, its invalid.
You cannot change resourceBase from the jetty-maven-plugin, as the jetty-maven-plugin itself needs to control that setting for its own purposes.
The jetty-maven-plugin will use the information that exists in the maven subsystem to build out a list of resourceBases to make your webapp valid from the point of view of the Servlet spec and maven. It will pull in information from:
Your project's build (eg: defined output directories in your effective pom)
Your project's plugins (eg: dynamically assigned output directories from your plugins, such as from maven-resources-plugin, maven-compiler-plugin, maven-war-plugin, jspc-maven-plugin, etc)
From the point of view of Jetty proper, you cannot have a WebAppContext that defines BOTH resourceBase and war, they are the same thing, and have the same purpose.
resourceBase is the fundamental concept within Jetty (and is how the jetty-maven-plugin initializes your webapp)
war is the specialized resourceBase for the Servlet spec. (and only used when you have a proper *.war or expanded webapp deployable. this is not valid during jetty-maven-plugin execution)
For configuring contextPath, use the jetty-maven-plugin <configuration> instead.
If you have this Jetty IoC Context XML for the purposes of configuring a JNDI resource, consider just making it a normal configuration in your WEB-INF/jetty-env.xml file.
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="proj1DS" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/proj1</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost/mydb</Set>
<Set name="User">root</Set>
<Set name="Password">***</Set>
<Set name="UseUnicode">true</Set>
<Set name="CharacterEncoding">UTF-8</Set>
</New>
</Arg>
</New>
</Configure>

IllegalArgumentException when attempting to start jetty server using gradle plugin

I am trying to use the jetty gradle plugin to run a jetty server for functional testing. However, I am getting an java.lang.IllegalArgumentException: Object is not of type class org.mortbay.jetty.webapp.WebAppContext.
I have followed the example shown here and can't see what I am doing differently. The relevant part of the build file looks like this:
apply plugin: 'jetty'
dependencies {
providedRuntime 'com.h2database:h2:1.3.167'
providedRuntime 'commons-dbcp:commons-dbcp:1.4'
}
jettyRunWar {
httpPort = 8083
stopPort = 8085
stopKey = "stopKey"
jettyConfig = file("$projectDir/jetty-config/jetty.xml")
}
jettyStop {
stopPort = 8085
stopKey = "stopKey"
}
And my jetty.xml looks like:
<?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">/gateway</Set>
<New class="org.mortbay.jetty.plus.naming.Resource">
<Arg>
</Arg>
<Arg>jdbc/gateway</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="url">jdbc:h2:tcp://localhost/build/db; USER=sa</Set>
</New>
</Arg>
</New>
</Configure>
The stacktrace can be found here.
Any suggestions would be greatly appreciated.
My best guess is that it's a bug in the Jetty plugin. In general, the Jetty plugin is quite limited and outdated, and I recommend to try the arquillian-gradle-plugin instead. This is where Gradle's container support is heading.

Nexus / Jetty doesn't want to start anymore: Unresolved address

We have a Nexus server which worked fine until friday. Nexus was stopped and since we are unable to start it again but I can't figure out why ?
I think it's a Jetty problem. Here is the stack strace:
jvm 1 | 2012-08-13 09:31:10 WARN [er_start_runner] - org.mortbay.log - failed SelectChannelConnector#*:8080
jvm 1 | java.net.SocketException: Unresolved address
jvm 1 | at sun.nio.ch.Net.translateToSocketException(Net.java:58)
jvm 1 | at sun.nio.ch.Net.translateException(Net.java:84)
jvm 1 | at sun.nio.ch.Net.translateException(Net.java:90)
jvm 1 | at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:61)
jvm 1 | at org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:216)
The configuration is (jetty.xml):
<Configure id="Server" class="org.mortbay.jetty.Server">
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<Set name="host">${application-host}</Set>
<Set name="port">${application-port}</Set>
</New>
</Arg>
</Call>
<Set name="handler">
<New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection">
<!-- The following configuration is REQUIRED, and MUST BE FIRST.
It makes the Plexus container available for use in the Nexus webapp. -->
<Call name="addLifeCycleListener">
<Arg>
<New class="org.sonatype.plexus.jetty.custom.InjectExistingPlexusListener" />
</Arg>
</Call>
<!-- The following configuration disables JSP taglib support, the validation of which
slows down Jetty's startup significantly. -->
<Call name="addLifeCycleListener">
<Arg>
<New class="org.sonatype.plexus.jetty.custom.DisableTagLibsListener" />
</Arg>
</Call>
</New>
</Set>
<New id="NexusWebAppContext" class="org.mortbay.jetty.webapp.WebAppContext">
<Arg><Ref id="Contexts"/></Arg>
<Arg>${webapp}</Arg>
<Arg>${webapp-context-path}</Arg>
<Set name="extractWAR">false</Set>
</New>
<Set name="stopAtShutdown">true</Set>
<Set name="sendServerVersion">true</Set>
<Set name="sendDateHeader">true</Set>
<Set name="gracefulShutdown">1000</Set>
</Configure>
and the plexus.properties:
application-port=8081
application-host=0.0.0.0
runtime=${basedir}/runtime
apps=${runtime}/apps
nexus-work=${basedir}/../../data/nexus/sonatype-work/nexus
nexus-app=${runtime}/apps/nexus
webapp=${runtime}/apps/nexus/webapp
webapp-context-path=/nexus
security-xml-file=${nexus-work}/conf/security.xml
application-conf=${nexus-work}/conf
runtime-tmp=${runtime}/tmp
# If this file is present, it will be used to configure Jetty.
jetty.xml=${basedir}/conf/jetty.xml
# Uncomment this to use the debug js files
#index.template.file=templates/index-debug.vm
Nexus version is 1.9.2.3
I can't understand:
why it wants to start a connector at port 8080 (while I only set port 8081) and
what means the address * (and why not 0.0.0.0) ? And of course why it doesn't want to start anymore ?
Thanks a lot for all your ideas!
I cannot comment on the 8080 vs 8081 issue, but as for the SocketException ...
The SocketException: unresolved address is usually due to some sort of host/dns/resolve configuration issue present on your system.
The most basic testcase for java that might help identify the issue would be the following
import java.net.InetAddress;
import java.net.InetSocketAddress;
public class AddrTest
{
public static void main(String[] args)
{
try
{
InetAddress addr = InetAddress.getByName("0.0.0.0");
System.out.println("InetAddress => " + addr);
System.out.println("InetAddress.isAnyLocalAddress = " + addr.isAnyLocalAddress());
System.out.println("InetAddress.isLinkLocalAddress = " + addr.isLinkLocalAddress());
System.out.println("InetAddress.isLoopbackAddress = " + addr.isLoopbackAddress());
InetSocketAddress isockaddr = new InetSocketAddress(addr,8080);
System.out.println("InetSocketAddr = " + isockaddr);
System.out.println("InetSocketAddr.isUnresolved = " + isockaddr.isUnresolved());
}
catch (Throwable e)
{
e.printStackTrace();
}
}
}
Run this, and you should have the output
InetAddress => /0.0.0.0
InetAddress.isAnyLocalAddress = true
InetAddress.isLinkLocalAddress = false
InetAddress.isLoopbackAddress = false
InetSocketAddr = /0.0.0.0:8080
InetSocketAddr.isUnresolved = false
What's important to note are the 2 lines...
InetAddress.isAnyLocalAddress = true - means that java + OS reports this as the ANY addr
InetSocketAddr.isUnresolved = false - means that java + OS was able to resolve this socket address
If you get an exception during this test, then you have some sort of fundamental host resolution issue on your system (dns, dhcp. vpn, etc/hosts, no IPv4 available, etc...), nothing you do in java, jetty, or nexus can fix this sort of issue. You'll need to address this (no pun intended) at the OS / Networking level.
I had a similar issue. Jetty was running inside docker container (jetty:9.3.24-jre8). You need to comment out line about http.host in start.ini:
#jetty.http.host='0.0.0.0'
Network interfaces get mixed up for some reason.
Solved!
The file jetty.xml had only the 'r' permission which is not enough: it must have the 'x' permission too. So Jetty was unable to read the file jetty.xml and in that case it tries to start a default connector on '*:8080' => * is not resolvable (I don't know why they used * instead of 0.0.0.0 ???)
So it was a configuration issue.

Map external directory to web.xml

Is there an easy way to map a directory in the web.xml or other deployment descriptor (jetty.xml, etc) files?
For example, if I have a directory /opt/files/ is there a way that I can access its files and sub-directories by visiting http://localhost/some-mapping/? It strikes me that there should be some simple way of doing this, but I haven't been able to find out how (via google, stackoverflow, etc). All I've found are servlets that mimic fileservers, which is not what I would like.
For reference I am using jetty on an AIX box.
No idea how to do it with Jetty, but in Tomcat you can just add a new <Context> to server.xml:
<Context docBase="/opt/files" path="/files" />
This way it's accessible by http://example.com/files/.... See if something similar exist for Jetty.
Update: after Googling, the "normal Java code" equivalent would be something like:
WebAppContext files = new WebAppContext("/opt/files", "/files");
Server server = new Server(8080);
server.setHandler(files);
server.start();
Now yet to translate that into jetty.xml flavor. I am a bit guessing based on the documentation and examples found on the web, so don't pin me on it:
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="webApp">/opt/files</Set>
<Set name="contextPath">/files</Set>
</Configure>
Another possibility may be this:
<Configure class="org.mortbay.jetty.Server">
<Call name="addHandler">
<Arg>
<New class="org.mortbay.jetty.webapp.WebAppContext">
<Arg name="webApp">/opt/files</Arg>
<Arg name="contextPath">/files</Arg>
</New>
</Arg>
</Call>
</Configure>
After some more fiddling around, the best way to do this (for jetty) is to deploy a descriptor in the context directory that looks like the following...
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<!-- Configuration of a custom context. -->
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
<Call class="org.eclipse.jetty.util.log.Log" name="debug">
<!-- The default message to show if our context breaks. -->
<Arg>Configure context.xml</Arg>
</Call>
<!--
The context path is the web location of the context in relation to the
server address.
-->
<Set name="contextPath">/context</Set>
<!--
The resource base is the server directory to use for fetching files.
-->
<Set name="resourceBase">/path/to/files/on/server</Set>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="directoriesListed">true</Set>
<!-- For now we don't need any welcome files -->
<!--
<Set name="welcomeFiles"> <Array type="String">
<Item>index.html</Item> </Array> </Set>
-->
<!--
The cache time limit in seconds (ie max-age=3600 means that if the
document is older than 1 hour a fresh copy will be fetched).
-->
<Set name="cacheControl">max-age=3600,public</Set>
</New>
</Set>
</Configure>
I hope that this helps someone else!
I don't know that you can do that as a URL mapping, however files and folders in the same directory that your web.xml file is in will be accessible in the way you describe, although you can't control the mapping under your webapp.
Does that suit your needs?