How to start Jetty8 only for static content?

For testing purposes, I want to use Jetty 8 to serve only static content. I know how to start a web server from the command line:

java -jar start.jar jetty.port = 8082

I would like to be able to use vanilla Jetty, preferably 8 or 7, and run it using something like:

java -jar start.jar OPTIONS = resources resources.root = .. / foo jetty.port = 8082

Then the files should be accessible from the server root directory. A file named ../foo/x.html should be accessible via http://localhost:8082/x.html .

I do not want to create a WAR file or something interesting. Preferably, it should not do server-side caching, leaving files unlocked on Windows computers. In addition, I only want to serve files, even those in subdirectories, without a browser with fantastic files or how to change them with the client.

Is it possible? If not, what is the minimum configuration required to perform this behavior?

Additional Information

I tried the following command. I was expecting you to be able to view the javadoc shipped with Jetty 8 with http://localhost:8080/javadoc/ , but it always gives me 404

java -jar start.jar --ini OPTIONS = Server, resources etc / jetty.xml contexts / javadoc.xml

+6
source share
3 answers

The easiest way to start Jetty and make it serve static content is to use 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> 

How can you start Jetty using:

 java -jar start.jar --ini static-content.xml files.base=./foo jetty.port=8082 

If you omit files.base, the current pointer will be used; if you omit jetty.port, port 8080 will be used.

--ini will disconnect the settings from start.ini, so also make sure that no other handlers, etc. will not be activated.

+5
source

A bit offtopic, but someone using maven might wish for something like this (suppose the static resources were copied to target/web ):

 <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.9.v20130131</version> <executions> <execution> <id>start-jetty</id> <phase>install</phase> <goals> <goal>start</goal> </goals> <configuration> <webAppConfig> <resourceBases> <contextPath>/</contextPath> <resourceBase>${project.build.directory}/web</resourceBase> </resourceBases> </webAppConfig> </configuration> </execution> </executions> </plugin> 
+1
source

In your distribution, under the context directory is javadoc.xml, which you can use as an example of how to do this quite easily.

http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-distribution/src/main/resources/contexts/javadoc.xml

this is what actually looks like

you want to change the context path and resource base

I would also recommend simply removing jetty-webapps.xml from the launch in the start.ini file, as well as deleting context files that you do not want to deploy with

you can see how to set some other parameters in the start.ini file if you like

http://wiki.eclipse.org/Jetty/Feature/Start.jar

go here for process start information

amuses

0
source

Source: https://habr.com/ru/post/919246/


All Articles