0

I have one jar file with set of Servlets, Filters and a web-fragment.xml file defined inside META-INF folder. I'm including this jar in my second war project. The war project has the web.xml with metadata-complete=false, and I'm using gradle to build the project.

If I deploy the war in to a standalone servlet container Jetty or Tomcat, it finding the web-fragment.xml correctly and the webpages are loading properly. But this is not happening when I do the Jetty setup myself for integration testing.

The Jetty APIs I used is given bellow,

            _server = new Server(8080);
            _server.setStopAtShutdown(true);

            WebAppContext webAppContext = new WebAppContext();
            webAppContext.setContextPath("/");
            webAppContext.setParentLoaderPriority(true);
            webAppContext.setResourceBase("src/main/webapp");

            _server.setHandler(webAppContext);
            _server.start();

By default the WebAppContext class using the following configurations, from that I can see FragmentConfiguration is there.

public static final String[] DEFAULT_CONFIGURATION_CLASSES =
    {
        "org.eclipse.jetty.webapp.WebInfConfiguration",
        "org.eclipse.jetty.webapp.WebXmlConfiguration",
        "org.eclipse.jetty.webapp.MetaInfConfiguration",
        "org.eclipse.jetty.webapp.FragmentConfiguration",
        "org.eclipse.jetty.webapp.JettyWebXmlConfiguration"
    } ;

Why it's not working when I'm using the Jetty APIs myself, Am I missing any classpath / classloader related configuration here or something else ? please help me to find it out.

Thank you.

Haridas N
  • 529
  • 5
  • 20
  • if you are doing integration testing, don't use `webAppContext.setParentLoaderPriority(true)` - that would be an advanced feature that results in an inversion of the servlet classloader behavior (making your integration test far different / out of spec to a standalone server) – Joakim Erdfelt Nov 05 '15 at 13:48
  • Are there any annotations present in your main webapp or fragment? – Joakim Erdfelt Nov 05 '15 at 13:49
  • No annotations are being used. Servlets and Filters are registered with the web-fragment.xml. I will try with `webAppContext.setParentLoaderPriority(true)` removed. – Haridas N Nov 05 '15 at 14:00
  • Removal of webAppContext.setParentLoaderPriority(true) doesn't make any difference. Still as before. – Haridas N Nov 05 '15 at 14:19
  • This could be a solution - http://akhikhl.github.io/gretty-doc/Integration-tests-support.html gradle gretty plugin has the notion of integrationTest and they are designed in such a way we can couple our integration test tasks so simply. Will explore this direction. I also checked the gradle jetty plugin code base, looks like lot of configurations are done before making the jetty ready to serve. – Haridas N Nov 06 '15 at 12:10
  • Hi, did you solve this? – sagioto Jul 10 '16 at 13:32

0 Answers0