码头静态网页内容

问题描述

上周我尝试了一百万种不同的方法来让码头呈现一个简单的静态 html 文件。但它一直给我 404 结果。

设置是:

  • Jetty 安装在:/usr/lib/jetty-home-11.0.2
  • Jetty 基础目录:~/Documents/projects/jetty/statWebApp/jetty_base
  • 安装的模块是http。 (start.jar --add-module=http)

在 ${jetty.base}/webapps 中有两个文件 index.html 和 web.xml

web.xml 是:

<?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>

服务器启动时: ${jetty.base}/webapps java -jar /usr/lib/jetty-home-11.0.2/start.jar

我希望在浏览到 http://localhost:8080/ 时看到 index.html 文件

我得到了码头呈现的 404 页面。因此,我知道服务器已启动,但未显示页面

非常欢迎任何有关让 Jetty 工作的帮助。

解决方法

我已经添加了部署模块(start.jar --add-module=http,deploy)。 然后我更改了 html 文件的路径。

<Set name ="resourceBase">/home/edwin/Documents/projects/jetty/statWeb/jetty_base/webapps/</Set>

或者通过相对路径

<Set name ="resourceBase">./webapps/</Set>

两者都有效。