void awaitTermination() { tomcat.getServer().await(); } }
/** * Blocks and waits until the server shuts down. */ public void await() { Server server; synchronized (this) { server = tomcat.getServer(); } server.await(); // Can't do this with lock held }
@Override public void run() { TomcatWebServer.this.tomcat.getServer().await(); }
String webappDirLocation = "src/main/webapp/"; Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); StandardContext ctx = (StandardContext) tomcat.addWebapp("/embeddedTomcat", new File(webappDirLocation).getAbsolutePath()); //declare an alternate location for your "WEB-INF/classes" dir: File additionWebInfClasses = new File("target/classes"); WebResourceRoot resources = new StandardRoot(ctx); resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/")); ctx.setResources(resources); tomcat.start(); tomcat.getServer().await();
private void addPreviouslyRemovedConnectors() { Service[] services = this.tomcat.getServer().findServices(); for (Service service : services) { Connector[] connectors = this.serviceConnectors.get(service); if (connectors != null) { for (Connector connector : connectors) { service.addConnector(connector); if (!this.autoStart) { stopProtocolHandler(connector); } } this.serviceConnectors.remove(service); } } }
String webappDirLocation = "src/main/webapp/"; Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); StandardContext ctx = (StandardContext) tomcat.addWebapp("/embeddedTomcat", new File(webappDirLocation).getAbsolutePath()); //declare an alternate location for your "WEB-INF/classes" dir: File additionWebInfClasses = new File("target/classes"); VirtualDirContext resources = new VirtualDirContext(); resources.setExtraResourcePaths("/WEB-INF/classes=" + additionWebInfClasses); ctx.setResources(resources); tomcat.start(); tomcat.getServer().await();
private void removeServiceConnectors() { for (Service service : this.tomcat.getServer().findServices()) { Connector[] connectors = service.findConnectors().clone(); this.serviceConnectors.put(service, connectors); for (Connector connector : connectors) { service.removeConnector(connector); } } }
public synchronized void start() throws IOException { if (id != null) { log.info("Starting Serving Layer {}", id); } Preconditions.checkState(tomcat == null); // Has to happen very early before Tomcat init: System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true"); noSuchBaseDir = Files.createTempDirectory("Oryx"); noSuchBaseDir.toFile().deleteOnExit(); Tomcat tomcat = new Tomcat(); Connector connector = makeConnector(); configureTomcat(tomcat, connector); configureEngine(tomcat.getEngine()); configureServer(tomcat.getServer()); configureHost(tomcat.getHost()); makeContext(tomcat, noSuchBaseDir); try { tomcat.start(); } catch (LifecycleException le) { throw new IOException(le); } this.tomcat = tomcat; }
void terminate() { if (tomcat.getServer().getState().isAvailable()) { try { tomcat.stop(); tomcat.destroy(); } catch (Exception e) { Loggers.get(EmbeddedTomcat.class).error("Fail to stop web server", e); } } deleteQuietly(tomcatBasedir()); }
tomcat.getServer().await();
/** * Start the server. * * @throws LifecycleException Start error */ public void start() throws LifecycleException { getServer(); server.start(); }
/** * Stop the server. * * @throws LifecycleException Stop error */ public void stop() throws LifecycleException { getServer(); server.stop(); }
/** * Get the service object. Can be used to add more * connectors and few other global settings. * @return The service */ public Service getService() { return getServer().findServices()[0]; }
/** * Destroy the server. This object cannot be used once this method has been * called. * * @throws LifecycleException Destroy error */ public void destroy() throws LifecycleException { getServer(); server.destroy(); // Could null out objects here }
/** * Initialize the server. * * @throws LifecycleException Init error */ public void init() throws LifecycleException { getServer(); server.init(); }
/** * Stop the server. * * @throws LifecycleException */ public void stop() throws LifecycleException { getServer(); server.stop(); }
@Override public void run() { TomcatStarter.this.tomcat.getServer().await(); } };
/** * Initialize the server. * * @throws LifecycleException Init error */ public void init() throws LifecycleException { getServer(); server.init(); }
public static void main(String[] args) throws Exception { Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); //actually deploy stuff on your tomcat by defining contexts tomcat.start(); tomcat.getServer().await(); }