public static void main(String[] args) throws Exception { String configPort = "8080"; if(args.length > 0){ configPort = args[0]; } String port = System.getProperty("server.http.port", configPort); System.out.println("Server started on port: " + port); Server server = new Server(); server.setConnectors(new Connector[]{createConnector(server, Integer.parseInt(port))}); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); context.setContextPath("/api"); ServletHolder servletHolder = new ServletHolder(createJerseyServlet()); servletHolder.setInitOrder(1); context.addServlet(servletHolder, "/*"); WebAppContext webAppContext = new WebAppContext(); webAppContext.setServer(server); webAppContext.setContextPath("/"); String resourceBase = System.getProperty("resourceBase"); if(resourceBase != null){ webAppContext.setResourceBase(resourceBase); } else { webAppContext.setResourceBase(Main.class.getResource("/webapp").toExternalForm()); } HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[]{context, webAppContext}); server.setHandler(handlers); server.start(); server.join(); }
final WebAppContext context = new WebAppContext(null, "/", null, null, null, null, WebAppContext.NO_SESSIONS); context.addServlet(new ServletHolder(redirect), "/*"); context.setServer(masterJettyServer);
bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp");
sessionHandler.setServer( getJetty() ); final WebAppContext staticContext = new WebAppContext(); staticContext.setServer( getJetty() ); staticContext.setContextPath( mountPoint ); staticContext.setSessionHandler( sessionHandler );
ctx.setServer(server);
Server server = new Server(); ServerConnector http = new ServerConnector(server); http.setPort(8080); server.addConnector(http); WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp"); server.setHandler(bb); try { server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); System.exit(100); }
server = new Server(); SocketConnector connector = new SocketConnector(); connector.setPort(8080); server.setConnectors(new Connector[] { connector }); WebAppContext context = new WebAppContext(); context.setServer(server); context.setContextPath("/your-context"); context.setWar("path to war"); server.addHandler(context); Thread monitor = new MonitorThread(); monitor.start(); server.start(); server.join();
final Server server = new Server(); //skipped socketconnector initialization final WebAppContext js = new WebAppContext(); js.setServer(server); js.setContextPath("/js"); js.setWar("target/classes/js"); // or whatever the correct path is in your case server.addHandler(js); // css the same way final WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp"); server.addHandler(bb); server.start();
final Connector connector = new SelectChannelConnector(); connector.setPort(8080); final Server server = new Server(); server.addConnector(connector); server.setStopAtShutdown(true); final WebAppContext context = new WebAppContext(); context.setContextPath("/"); context.setServer(server); final ProtectionDomain protectionDomain = Main.class.getProtectionDomain(); final URL location = protectionDomain.getCodeSource().getLocation(); context.setWar(location.toExternalForm()); server.addHandler(context); server.start(); server.join();
final Server server = new Server(); //skipped socketconnector initialization final WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp"); final URL url = new File("target/classes").getAbsoluteFile().toURI().toURL(); final Resource resource = new FileResource(url); final ResourceHandler handler = new ResourceHandler(); handler.setBaseResource(resource); server.addHandler(handler); server.addHandler(bb); server.start();
webAppContext.setServer(server); server.setHandler(webAppContext);
context.setServer(server); context.setContextPath("/"); context.setWar("src/main/webapp");
/** * Gets the web app context. * * @param server * the server * @param projectname * the projectname * @return the web app context */ public static WebAppContext getWebAppContext(final Server server, final String projectname) { final File webapp = PathFinder.getProjectDirectory(); final File wa = PathFinder.getRelativePath(webapp, projectname, "src", "main", "webapp"); final WebAppContext webAppContext = new WebAppContext(); webAppContext.setServer(server); webAppContext.setContextPath("/"); webAppContext.setWar(wa.getAbsolutePath()); return webAppContext; }
context.setServer(server); context.setContextPath("/"); context.setExtractWAR(false);
context.setServer(server); context.setContextPath("/"); context.setExtractWAR(false);
public static void main(String[] args) throws Exception { Server server = new Server(); Connector context = new SocketConnector(); context.setServer(server); context.setPort(PORT); String webappDir = WEBAPP_DIR; if (args.length > 0) { webappDir = args[0]; } WebAppContext webapp = new WebAppContext(); webapp.setServer(server); webapp.setContextPath(WEBAPP_CTX); webapp.setResourceBase(webappDir); server.setHandler(webapp); server.setConnectors(new Connector[] { context }); server.start(); } }
public void start() throws Exception { server = new Server(port); WebAppContext webAppContext = new WebAppContext(); webAppContext.setContextPath("/"); webAppContext.setWar("zenvisage.war"); webAppContext.setParentLoaderPriority(true); webAppContext.setServer(server); webAppContext.setClassLoader(ClassLoader.getSystemClassLoader()); webAppContext.getSessionHandler().getSessionManager() .setMaxInactiveInterval(10); server.setHandler(webAppContext); server.start(); // ZvMain zvMain = (ZvMain) SpringApplicationContext.getBean("zvMain"); // zvMain.loadData(); DatabaseAutoLoader databaseAutoLoader = new DatabaseAutoLoader(this); databaseAutoLoader.run(); }
public String addRepository(String url) { if (urls.contains(url)) { return null; } String path = "/" + url.replace("://", "_") .replace(":", "_") .replace("/", "_") .replace(".", "_"); WebAppContext context = new WebAppContext(); context.setServer(server); context.setContextPath(path); context.setExtractWAR(false); context.setCopyWebInf(true); context.setWar(rubygemsWarURI); context.setInitParameter("gem-caching-proxy-url", url); context.setInitParameter("gem-caching-proxy-storage", new File(cachedir, path).getAbsolutePath()); // do not setup other repos context.setInitParameter("gem-proxy-storage", ""); context.setInitParameter("gem-hosted-storage", ""); context.setInitParameter("gem-merged", "false"); this.handlerCollection.addHandler(context); return path + "/caching/maven/releases"; }
public TWebServer duplicateContext(String existsContextPath,String duplicateContextPath) throws IllegalStateException{ WebAppContext context = contexts.get(existsContextPath); if(null == context){ throw new IllegalStateException("The given argument [existsContextPath] '" + existsContextPath + "' not exists"); } if(contexts.containsKey(duplicateContextPath)){ throw new IllegalStateException("The given argument [duplicateContextPath] '" + duplicateContextPath + "' aleady exists"); } WebAppContext duplicateContext = new WebAppContext(); duplicateContext.setContextPath(duplicateContextPath); duplicateContext.setClassLoader(context.getClassLoader()); duplicateContext.setParentLoaderPriority(context.isParentLoaderPriority()); duplicateContext.setServer(server); duplicateContext.setErrorHandler(context.getErrorHandler()); duplicateContext.setBaseResource(context.getBaseResource()); duplicateContext.setThrowUnavailableOnStartupException(context.isThrowUnavailableOnStartupException()); contexts.put(duplicateContextPath, duplicateContext); return this; }
private static ContextHandlerCollection prepareContexts() { MovedContextHandler handler = new MovedContextHandler(); handler.setContextPath("/membership"); handler.setNewContextURL("/#/membership"); handler.setPermanent(true); handler.setDiscardPathInfo(false); handler.setDiscardQuery(false); WebAppContext webAppContext = new WebAppContext(); webAppContext.setServer(server); webAppContext.setContextPath("/"); webAppContext.setWar("src/main/webapp"); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[] { handler, webAppContext }); return contexts; }