How do I start Jetty8 to only serve static content?
jetty
Solution
The simplest way to start Jetty and have it serve static content is by using the following xml file:
static-content.xml:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="FileServer" class="org.eclipse.jetty.server.Server">
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="8080"/></Set>
</New>
</Arg>
</Call>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="resourceBase"><Property name="files.base" default="./"/></Set>
</New>
</Set>
</Configure>
Than you can start Jetty using:
java -jar start.jar --ini static-content.xml files.base=./foo jetty.port=8082
If you omit files.base, the current direcory will be used; if you omit jetty.port, port 8080 will be used.
The `--ini` will disable the settings from start.ini, therefore also make sure no other handlers etc. will be activated.
Problem
For testing purposes I want to use Jetty 8 to serve only static content. I know how to start the webserver from the command line: java -jar start.jar jetty.port=8082 I would like to be able to use a vanilla Jetty, preferably 8 or 7, and start it using something like: java -jar start.jar OPTIONS=resources resources.root=../foo jetty.port=8082 The files should then be accessible from the root of the server. A file called `../foo/x.html` should be accessible via `http://localhost:8082/x.html`. I don't want to create a WAR file or anything fancy. Preferably it shouldn't do any caching on the server side, leaving the files unlocked on Windows machines. Also, I only want to serve files, even located in subdirectories, no fancy file browser or ways to modify them from a client. Is this possible? If not, what is the minimum configuration needed to accomplish such behavior? Additional information I've tried the following command. I expected to be able to browse the javadoc shipped with Jetty 8 using `http://localhost:8080/javadoc/`, but it always gives me a 404 java -jar start.jar --ini OPTIONS=Server,resources etc/jetty.xml contexts/javadoc.xml