Web services 从Jetty中web应用程序外部的文件夹提供文件

Web services 从Jetty中web应用程序外部的文件夹提供文件,web-services,jakarta-ee,jetty,static-files,Web Services,Jakarta Ee,Jetty,Static Files,我在Jetty服务器上有一个JavaWeb应用程序(Eclipse/OSGI)。我希望能够从web根目录之外的文件夹向web应用程序提供静态文件。在我的web应用程序中,我还不知道要提供的文件的文件名,因此我希望在启动web应用程序时将文件名(和/或路径)作为VM参数。例如: 我有一个映像-myImg.jpg-我把它放在服务器文件系统的一个文件夹中,例如root/images/myImg.jpg。我想将其作为一个VM参数,例如“-DmyImg=/images/myImg.jpg/”,这样我就可以

我在Jetty服务器上有一个JavaWeb应用程序(Eclipse/OSGI)。我希望能够从web根目录之外的文件夹向web应用程序提供静态文件。在我的web应用程序中,我还不知道要提供的文件的文件名,因此我希望在启动web应用程序时将文件名(和/或路径)作为VM参数。例如:

我有一个映像-myImg.jpg-我把它放在服务器文件系统的一个文件夹中,例如root/images/myImg.jpg。我想将其作为一个VM参数,例如“-DmyImg=/images/myImg.jpg/”,这样我就可以获得图像并将其显示在我的网页上。我怎样才能做到这一点?我可以在不创建新Servlet的情况下执行此操作吗

提前感谢您的帮助

解决了

这是我添加到jetty.xml文件中的内容:

<Set name="handler">
    <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
        <Set name="handlers">
            <Array type="org.eclipse.jetty.server.Handler">
                <Item>
                    <New class="org.eclipse.jetty.server.handler.ContextHandler">
                        <Set name="contextPath">/myContextPath</Set>
                        <Set name="handler">
                            <New class="org.eclipse.jetty.server.handler.ResourceHandler">
                                <Set name="directoriesListed">false</Set>
                                <Set name="resourceBase">/actual/folder/on/file/system</Set>
                            </New>
                        </Set>
                    </New>
                </Item>
                [...other handlers...]
            </Array>
        </Set>
    </New>
</Set>

/myContextPath
假的
/实际/文件夹/在/文件/系统上
[…其他处理程序…]

@Farna:在您的回答中,我无法理解您是如何将文件名作为VM参数传递的。这就是我所做的

我在jetty
webapps
目录中创建了
testparvez.xml
文件

    <?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.eclipse.org/configure.dtd">

<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
  <Set name="contextPath">/testparvez</Set>
  <Set name="resourceBase"><SystemProperty name="mydir"/></Set>
  <Set name="handler">
    <New class="org.eclipse.jetty.server.handler.ResourceHandler">
      <Set name="welcomeFiles">
        <Array type="String">
          <Item><SystemProperty name="myfile"/></Item>
        </Array>
      </Set>
      <Set name="cacheControl">max-age=3600,public</Set>
    </New>
  </Set>
</Configure>

最后,我从url
http://localhost:8082/testparvez/

我试图在jetty.xml配置文件中使用ContextHandler,其中我将baseResource指向文件系统上的实际文件夹,但当我尝试通过contextPath访问它时,资源为“null”。
java -jar start.jar jetty.port=8082 -Dmydir=C:/test/javadoc/ -Dmyfile=index.html