My application runs fine on embedded Jetty 9.2.11, but after assembling with the maven assembly plugin, only servlets declared in web.xml are served.
My jar contains WEB-INF/web.xml
using Servlet 3.0 format
A number of jars are placed in WEB-INF/lib
, each with META-INF/web-fragment.xml
. These are discovered perfectly well when run from NetBeans.
QueuedThreadPool pool = new QueuedThreadPool(20);
Server server = new Server(pool);
server.setStopAtShutdown(true);
ServerConnector connector = new ServerConnector(server);
connector.setPort(8888);
server.addConnector(connector);
pool.start();
connector.start();
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setDescriptor("WEB-INF/web.xml");
webapp.setDefaultsDescriptor("webdefault.xml");
webapp.setClassLoader(MyURIClassLoader);
webapp.setExtractWAR(false);
webapp.setCopyWebDir(false);
webapp.setConfigurationDiscovered(true);
List<String> configs = new ArrayList<>(5);
configs.add("org.eclipse.jetty.webapp.WebInfConfiguration");
configs.add("org.eclipse.jetty.webapp.WebXmlConfiguration");
configs.add("org.eclipse.jetty.webapp.MetaInfConfiguration");
configs.add("org.eclipse.jetty.webapp.FragmentConfiguration");
configs.add("org.eclipse.jetty.webapp.JettyWebXmlConfiguration");
webapp.setConfigurationClasses(configs);
ContextHandlerCollection container = new ContextHandlerCollection();
container.setHandlers(handlers.toArray(new Handler[handlers.size()]));
server.setHandler(new HTTPGlobalHandler(container));
server.start();
All web.xml
and web-fragment.xml
files are pretty standard. Nothing but servlets and security settings including CORS.
The structure of the assembly is as follows:
/boot.jar (our in-house launcher with a custom URIClassLoader)
|- /modules/ (a folder including our target jar with ALL dependencies provided)
|- target.jar (containing the WEB-INF/lib folder with fragment-holding jars)