import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; public class JettyServer { public static void main(String[] args) { Server server = new Server(8080); WebAppContext context = new WebAppContext(); context.setResourceBase("../webapp-project/WebContent"); context.setDescriptor("../webapp-project/WebContent/WEB-INF/web.xml"); context.setContextPath("/"); context.setParentLoaderPriority(true); server.setHandler(context); try { server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); } } }
/** * Create the web context for the application of specified name */ WebAppContext createWebAppContext(Builder b) { WebAppContext ctx = new WebAppContext(); setContextAttributes(ctx.getServletContext(), b.contextAttrs); ctx.setDisplayName(b.name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + b.name); return ctx; }
masterJettyServer = new Server(); final ServerConnector connector = new ServerConnector(masterJettyServer); connector.setHost(addr); final WebAppContext context = new WebAppContext(null, "/", null, null, null, null, WebAppContext.NO_SESSIONS); context.addServlet(new ServletHolder(redirect), "/*"); context.setServer(masterJettyServer); masterJettyServer.start(); } catch (Exception e) { throw new IOException("Failed to start redirecting jetty server", e);
public class Jetty { public static Server createServer(int port) { Server server = new Server(port); WebAppContext context = new WebAppContext(); context.setResourceBase("src/main/webapp"); context.setClassLoader(Thread.currentThread().getContextClassLoader()); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[]{context}); server.setHandler(handlers); return server; } }
WebAppContext htrootContext = new WebAppContext(); htrootContext.setContextPath("/"); ipaccess.setHandler(securityHandler); LoklakServer.server.setHandler(ipaccess);
... WebAppContext webapp = new WebAppContext(); // classURLs may contains URL to WEB-INF/classes or WEB-INF/lib/additional_jar of you web app URLClassLoader classLoader = new URLClassLoader(classURLs.toArray(new URL[classURLs.size()]), Thread.currentThread().getContextClassLoader()); webapp.setClassLoader(classLoader); ... ContextHandlerCollection contextCollection = new ContextHandlerCollection(); contextCollection.addHandler(webapp); ... Server server = new Server(threadPool); server.setHandler(contextCollection); server.start(); ...
Server server = new Server(8080); Configuration.ClassList classlist = Configuration.ClassList .setServerDefault(server); classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration"); classlist.addBefore( "org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration"); WebAppContext context = new WebAppContext(); context.setContextPath("/"); // ... etc ...
public EmbeddedWebServer(BimServer bimServer, String resourceBase, boolean localDev) { server = new Server(new QueuedThreadPool(200, 20)); socketConnector.setStopTimeout(10800000); // 3 hours for bulkcheckin server.addConnector(socketConnector); context = new WebAppContext(server, "", "/"); context.setTempDirectory(bimServer.getHomeDir().resolve("jettytmp").toFile());
WebAppContext webapp = new WebAppContext(); webapp.setContextPath(webAppContext); webapp.setWar(warFilePath); webapp.setParentLoaderPriority(false); logger.info("Attempting to start HTTP service on port ({}) at bind-address ({})...", this.port, this.bindAddress); httpServer.start(); } else { webapp.start();
public static void main(String[] args) throws Exception { String weppAppHome = args[0]; Integer port = 8080; Server server = new Server(port); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setCompactPath(true); webapp.setDescriptor(weppAppHome + "/WEB-INF/web.xml"); webapp.setResourceBase(weppAppHome); webapp.setParentLoaderPriority(true); server.setHandler(webapp); server.start(); server.join(); }
public static Server createServer(int port) throws MalformedURLException, URISyntaxException { Server server = new Server(); server.setStopAtShutdown(true); ServerConnector connector = new ServerConnector(server); connector.setPort(port); connector.setReuseAddress(true); server.setConnectors(new Connector[]{connector}); WebAppContext webContext = new WebAppContext("webapp", CONTEXT); webContext.setBaseResource(Resource.newResource(new URL(ApiWebSite.class.getResource("/webapp/WEB-INF"), "."))); webContext.setClassLoader(ApiWebSite.class.getClassLoader()); server.setHandler(webContext); return server; }
Server server = new Server(0); WebAppContext webAppContext = new WebAppContext("src/main/webapp", "/"); server.addHandler(webAppContext); server.start(); webServerPort = server.getConnectors()[0].getLocalPort();
final String classpath = configuration.getClasspath(); WebAppContext ctx = new WebAppContext(); ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); ctx.setContextPath(path); server.setHandler(ctx);
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();
public JettyEmbeddedServer() { server = new Server(); server.setStopAtShutdown(true); connector = new ServerConnector(server); context = new WebAppContext(); }
private WebAppContext loadWar(final File warFile, final String contextPath, final ClassLoader parentClassLoader) { final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath); webappContext.setContextPath(contextPath); webappContext.setDisplayName(contextPath);
Server server = new Server( port ); WebAppContext root = new WebAppContext(); root.setWar("/path/to/somewhere"); root.setContextPath("/"); server.addHandler( root ); server.start();
@Override public void start() { LOG.info("Starting Kaa Admin Web Server..."); server = new Server(adminPort); webAppContext = new WebAppContext(); webAppContext.setEventListeners(new EventListener[]{adminContextLoaderListener}); webAppContext.setContextPath("/"); String webXmlLocation = AdminInitializationService.class.getResource("/admin-web/WEB-INF/" + webXmlFile).toString(); webAppContext.setDescriptor(webXmlLocation); String resLocation = AdminInitializationService.class.getResource("/admin-web").toString(); webAppContext.setResourceBase(resLocation); webAppContext.setParentLoaderPriority(true); server.setHandler(webAppContext); try { server.start(); LOG.info("Kaa Admin Web Server started."); } catch (Exception ex) { LOG.error("Error starting Kaa Admin Web Server!", ex); } }
public static Server createServer(int port) throws MalformedURLException, URISyntaxException { Server server = new Server(); server.setStopAtShutdown(true); ServerConnector connector = new ServerConnector(server); connector.setPort(port); connector.setReuseAddress(true); server.setConnectors(new Connector[]{connector}); WebAppContext webContext = new WebAppContext("webapp", CONTEXT); webContext.setBaseResource(Resource.newResource(new URL(ApiWebSite.class.getResource("/webapp/WEB-INF"), "."))); webContext.setClassLoader(ApiWebSite.class.getClassLoader()); server.setHandler(webContext); return server; }
Server server = new Server(8080); server.setStopAtShutdown(true); WebAppContext webAppContext = new WebAppContext(); webAppContext.setContextPath("/app"); webAppContext.setResourceBase("src/main/webapp"); webAppContext.setClassLoader(getClass().getClassLoader()); server.addHandler(webAppContext); server.start(); URL url = new URL("http://localhost:8080/app/some_call"); URLConnection connection = url.openConnection(); List<String> lines = IOUtils.readLines(connection.getInputStream()); System.out.println(lines.get(0));