配置 Jetty 9.2 以允许通过 XML 文件的符号链接

问题描述

我的设置有点复杂,因为我使用带有 Warbler 的 JRuby,它在下面使用 Jetty 9.2.9。

现在,the docs for enabling symlinks in Jetty 告诉您将其添加WEB-INF/jetty-web.xml

  <!-- Allow symbolic links  -->
  <Call name="addaliasCheck">
    <Arg><New class="org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker"/></Arg>
  </Call>

但是,据我通过在 GitHub 上搜索使用 AllowSymLinkAliasChecker 的 XML 文件得知,此代码段必须在 <Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext"> 元素中使用。

通过 Warbler,我只能访问三个文件

  • web.xml 具有 <web-app> 元素
  • webserver.xml 具有 <Configure class="org.eclipse.jetty.server.Server"> 元素
  • webserver.properties 为 Jetty runner 定义了一堆参数

所以我的问题是,仅访问这三个文件(并且可能能够将更多文件添加WEB-INF 目录中),如何让 Jetty 遵循符号链接

解决方法

呃,好吧,显然如果我需要配置 WebAppContext,我可以将 jetty-web.xml 添加到我的 WEB-INF 文件夹和 Jetty will automatically use it

所以最后我的 jetty-web.xml 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE 
Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://www.eclipse.org/jetty/configure.dtd">
<!-- https://www.eclipse.org/jetty/documentation/jetty-9/index.html#jetty-web-xml-config -->
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <!-- https://www.eclipse.org/jetty/documentation/jetty-9/index.html#file-alias-serving -->
  <Call name="addAliasCheck">
    <Arg>
      <New class="org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker" />
    </Arg>
  </Call>
</Configure>