Spring application with embedded jetty can't find webdefault.xml if running from jar

前端 未结 6 651
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 15:19

I have spring application which uses embedded Jetty instance.

project
   | src
      | controller
      | webapps
          | jsp
          | WEB-INF
                    


        
6条回答
  •  眼角桃花
    2021-02-03 15:46

    Probably a little bit out-dated. However I recently encountered this problem in the context of embedding Jetty in an Eclipse OSGi application using the version of Jetty packaged with Eclipse (Jetty 8.x).

    The way I sorted this out is the following :

    1. Get the URL of the webdefault.xml relative to the org.eclipse.jetty.webapp bundle
    2. Pass this URL to the context default descriptor
    Bundle bundle = FrameworkUtil.getBundle(WebAppContext.class);
    Enumeration urls = bundle.findEntries("/", "webdefault.xml", true);
    String webdefaultURL = urls.nextElement().toExternalForm(); // Should check returned value 
    mycontext.setDefaultsDescriptor(webdefaultURL);
    

    Hope it helps

    seb

提交回复
热议问题