Embedded Jetty looking for files inside its Jar file

后端 未结 4 1400
误落风尘
误落风尘 2020-12-14 08:15

I successfully embedded Jetty on a test application. It can serve files without issues. Now I want to know if it\'s possible for Jetty to serve files that are inside its own

4条回答
  •  天涯浪人
    2020-12-14 08:57

    An example is listed on the Jetty embedding page at http://docs.codehaus.org/display/JETTY/Embedding+Jetty

    The trick is to create a File URL to your classpath location.

    String webDir = this.class.getClassLoader().getResource("com/company/project/mywebdir").toExternalForm();
    
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.setResourceBase(webDir);
    

提交回复
热议问题