繁体   English   中英

如何启动Jetty8仅提供静态内容?

[英]How do I start Jetty8 to only serve static content?

出于测试目的,我想使用Jetty 8仅提供静态内容。 我知道如何从命令行启动Web服务器:

java -jar start.jar jetty.port = 8082

我希望能够使用香草码头,最好是8或7,并使用以下内容启动它:

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

然后可以从服务器的根目录访问这些文件。 应该可以通过http://localhost:8082/x.html访问名为../foo/x.html的文件。

我不想创建一个WAR文件或任何花哨的东西。 最好不要在服务器端进行任何缓存,使文件在Windows机器上解锁。 此外,我只想提供文件,甚至位于子目录中,没有花哨的文件浏览器或从客户端修改它们的方法。

这可能吗? 如果没有,完成此类行为所需的最低配置是什么?

附加信息

我试过以下命令。 我希望能够使用http://localhost:8080/javadoc/浏览Jetty 8附带的http://localhost:8080/javadoc/ ,但它总能给我一个404

java -jar start.jar --ini OPTIONS =服务器,资源等/ jetty.xml contexts / javadoc.xml

启动Jetty并使其提供静态内容的最简单方法是使用以下xml文件:

静态的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>

你可以使用以下方式启动Jetty:

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

如果省略files.base,将使用当前的目录; 如果省略jetty.port,将使用端口8080。

--ini将禁用--ini的设置,因此也确保不会激活其他处理程序等。

有点offtopic,但有人使用maven可能希望这样的事情(假设静态资源已被复制到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>

在contextxts目录下的发行版中有一个javadoc.xml,您可以将其作为一个示例来说明如何轻松地完成此操作。

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

这就是它的实际情况

您正在寻找更改上下文路径和资源库

还建议只从start.ini文件中的启动中删除jetty-webapps.xml,并删除不想部署的上下文文件

您可以查看在start.ini文件中设置其他一些选项,如果您愿意的话

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

去那里获取开始过程的信息

干杯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM