您必须按如下方式配置 Jetty 服务器:
public class Application {
public static void main(String... args) throws Exception {
new Application().run(8080, "/");
}
public void run(int port, String contextPath) throws Exception {
URL webRootLocation = this.getClass().getResource("/META-INF/resources/");
URI webRootUri = webRootLocation.toURI();
WebAppContext context = new WebAppContext();
context.setBaseResource(Resource.newResource(webRootUri));
context.setContextPath(contextPath);
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*");
context.setConfigurationDiscovered(true);
context.setConfigurations(new Configuration[]{
new AnnotationConfiguration(),
new WebInfConfiguration(),
new WebXmlConfiguration(),
new MetaInfConfiguration(),
new FragmentConfiguration(),
new EnvConfiguration(),
new PlusConfiguration(),
new JettyWebXmlConfiguration()
});
context.getServletContext().setExtendedListenerTypes(true);
context.addEventListener(new ServletContextListeners());
Server server = new Server(port);
server.setHandler(context);
server.start();
server.join();
}
}
此外,maven-shade-plugin
如果要将工件打包为 uber-jar,则需要使用 。
您可以在https://github.com/alejandro-du/embedded-jetty-demo找到 Vaadin 12+ 的示例