Embedded Jetty looking for files inside its Jar file

后端 未结 4 1407
误落风尘
误落风尘 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:55

    It's pretty simple, if you throw Spring into the equation. And here it goes:

     ...
    
     WebAppContext webAppContext = new WebAppContext();
     webAppContext.setServer(server);
     webAppContext.setContextPath("/");
     webAppContext.setResourceBase(new ClassPathResource("webapp").getURI().toString());
    
     server.addHandler(webAppContext); 
    
     ....
    

    That will make jetty find the necessary web resources inside the jar file.

提交回复
热议问题