Project Example: https://github.com/jetty-project/embedded-servlet-3.0
You will still need WEB-INF/web.xml , but it may be empty . This means that the level of servlet support and metadata can be known.
Example: empty servlet 3.0 web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="false" version="3.0"> </web-app>
Then you can follow EmbedMe.java for an example on how to install this.
public class EmbedMe { public static void main(String[] args) throws Exception { int port = 8080; Server server = new Server(port); String wardir = "target/sample-webapp-1-SNAPSHOT"; WebAppContext context = new WebAppContext(); context.setResourceBase(wardir); context.setDescriptor(wardir + "WEB-INF/web.xml"); context.setConfigurations(new Configuration[] { new AnnotationConfiguration(), new WebXmlConfiguration(), new WebInfConfiguration(), new TagLibConfiguration(), new PlusConfiguration(), new MetaInfConfiguration(), new FragmentConfiguration(), new EnvConfiguration() }); context.setContextPath("/"); context.setParentLoaderPriority(true); server.setHandler(context); server.start(); server.join(); } }
source share