public static void main(String[] args) throws Exception { Server server = new Server(80); WebAppContext webapp = new WebAppContext(); webapp.setResourceBase("/"); webapp.setContextPath("/*"); webapp.setConfigurations( new Configuration[] { new WebXmlConfiguration(), new AnnotationConfiguration() { @Override public void preConfigure(WebAppContext context) throws Exception { ClassInheritanceMap map = new ClassInheritanceMap(); map.put( WebApplicationInitializer.class.getName(), new ConcurrentHashSet<String>() { { add(Initializer.class.getName()); add(SpringSecurityInitializer.class.getName()); } }); context.setAttribute(CLASS_INHERITANCE_MAP, map); _classInheritanceHandler = new ClassInheritanceHandler(map); } } }); server.setHandler(webapp); server.start(); System.out.println("Application started!"); server.join(); }
@Test public void testCluster() throws Exception { String projectBaseDirectory = System.getProperty("user.dir"); // // Create master node // Server masterServer = new Server(8080); WebAppContext masterContext = new WebAppContext(); masterContext.setDescriptor(projectBaseDirectory + "/target/vaporware/WEB-INF/web.xml"); masterContext.setResourceBase(projectBaseDirectory + "/target/vaporware"); masterContext.setContextPath("/"); masterContext.setConfigurations( new Configuration[] { new WebInfConfiguration(), new WebXmlConfiguration(), new MetaInfConfiguration(), new FragmentConfiguration(), new EnvConfiguration(), new PlusConfiguration(), new AnnotationConfiguration(), new JettyWebXmlConfiguration(), new TagLibConfiguration() }); masterContext.setParentLoaderPriority(true); masterServer.setHandler(masterContext); masterServer.start(); // masterServer.join(); // // Create slave node // Server slaveServer = new Server(8181); WebAppContext slaveContext = new WebAppContext(); slaveContext.setDescriptor(projectBaseDirectory + "/target/vaporware/WEB-INF/web-slave.xml"); slaveContext.setResourceBase(projectBaseDirectory + "/target/vaporware"); slaveContext.setContextPath("/"); slaveContext.setConfigurations( new Configuration[] { new WebInfConfiguration(), new WebXmlConfiguration(), new MetaInfConfiguration(), new FragmentConfiguration(), new EnvConfiguration(), new PlusConfiguration(), new AnnotationConfiguration(), new JettyWebXmlConfiguration(), new TagLibConfiguration() }); slaveContext.setParentLoaderPriority(true); slaveServer.setHandler(slaveContext); slaveServer.start(); // slaveServer.join(); // Try to let the user terminate the Jetty server instances gracefully. This won't work in an // environment like Eclipse, if // console input can't be received. However, even in that that case you will be able to kill // the Maven process without // a Java process lingering around (as would be the case if you used "Sever.join()" to pause // execution of this thread). System.out.println("PRESS <ENTER> TO HALT SERVERS (or kill the Maven process)..."); Scanner scanner = new Scanner(System.in); String line = scanner.nextLine(); System.out.println(line); scanner.close(); masterServer.stop(); slaveServer.stop(); System.out.println("Servers halted"); }