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();
public static void main(String[] args) throws Exception { String webappsPath = args[0]; int port = Integer.parseInt( args[1] ); File dataDir = Files.createTempDir(); dataDir.deleteOnExit(); Tomcat tomcat = new Tomcat(); tomcat.setBaseDir(dataDir.getAbsolutePath()); tomcat.setPort(port); tomcat.getConnector().setAttribute("maxThreads", "1000"); tomcat.addWebapp("/", new File(webappsPath).getAbsolutePath()); logger.info("-----------------------------------------------------------------"); logger.info("Starting Tomcat port {} dir {}", port, webappsPath); logger.info("-----------------------------------------------------------------"); tomcat.start(); while ( true ) { Thread.sleep(1000); } }
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();
@Override public void start() throws Exception { this.tomcatServer.start(); this.port = this.tomcatServer.getConnector().getLocalPort(); this.context.addLifecycleListener(event -> { if (logger.isDebugEnabled()) { logger.debug("Event: " + event.getType()); } }); }
@Override protected void startInternal() throws LifecycleException { this.tomcatServer.start(); setPort(this.tomcatServer.getConnector().getLocalPort()); }
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; }
@Override public void start() throws Exception { super.start(); String workingDir = System.getProperty("java.io.tmpdir"); tomcat = new Tomcat(); tomcat.setPort(8173); tomcat.setBaseDir(workingDir); tomcat.addWebapp("", webRoot.getAbsolutePath()); tomcat.start(); }
tomcat.start(); } catch (LifecycleException e) { throw new IllegalStateException("Failed to start tomcat server at " + url.getAddress(), e);
tomcat.start(); } catch (LifecycleException e) { throw new IllegalStateException("Failed to start tomcat server at " + url.getAddress(), e);
this.tomcat.start();
void start() { // '%2F' (slash /) and '%5C' (backslash \) are permitted as path delimiters in URLs System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true"); System.setProperty("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE", "true"); tomcat = new Tomcat(); // Initialize directories String basedir = tomcatBasedir().getAbsolutePath(); tomcat.setBaseDir(basedir); tomcat.getHost().setAppBase(basedir); tomcat.getHost().setAutoDeploy(false); tomcat.getHost().setCreateDirs(false); tomcat.getHost().setDeployOnStartup(true); new TomcatAccessLog().configure(tomcat, props); TomcatConnectors.configure(tomcat, props); webappContext = new TomcatContexts().configure(tomcat, props); try { tomcat.start(); new TomcatStartupLogs(Loggers.get(getClass())).log(tomcat); } catch (LifecycleException e) { Loggers.get(EmbeddedTomcat.class).error("Fail to start web server", e); Throwables.propagate(e); } }
tomcat.start(); port1 = tomcat.getConnector().getLocalPort();
wrapper.setAsyncSupported(true); ctx.addServletMappingDecoded("/*", "webdav"); tomcat.start(); port1 = tomcat.getConnector().getLocalPort();
@Override protected void configure(ServerBuilder sb) throws Exception { // Prepare Tomcat instances. tomcatWithWebApp = new Tomcat(); tomcatWithWebApp.setPort(0); tomcatWithWebApp.setBaseDir("build" + File.separatorChar + "tomcat-" + UnmanagedTomcatServiceTest.class.getSimpleName() + "-1"); tomcatWithWebApp.addWebapp("", WebAppContainerTest.webAppRoot().getAbsolutePath()); TomcatUtil.engine(tomcatWithWebApp.getService(), "foo").setName("tomcatWithWebApp"); tomcatWithoutWebApp = new Tomcat(); tomcatWithoutWebApp.setPort(0); tomcatWithoutWebApp.setBaseDir("build" + File.separatorChar + "tomcat-" + UnmanagedTomcatServiceTest.class.getSimpleName() + "-2"); assertThat(TomcatUtil.engine(tomcatWithoutWebApp.getService(), "bar")).isNotNull(); // Start the Tomcats. tomcatWithWebApp.start(); tomcatWithoutWebApp.start(); // Bind them to the Server. sb.serviceUnder("/empty/", TomcatService.forConnector("someHost", new Connector())) .serviceUnder("/some-webapp-nohostname/", TomcatService.forConnector(tomcatWithWebApp.getConnector())) .serviceUnder("/no-webapp/", TomcatService.forTomcat(tomcatWithoutWebApp)) .serviceUnder("/some-webapp/", TomcatService.forTomcat(tomcatWithWebApp)); } };
@Override public void afterPropertiesSet() throws Exception { this.tomcatServer.start(); }
tomcat.start(); } catch (LifecycleException e) { log.error("Unable to launch Tomcat", e);
public static void main(String[] args) throws Exception { ApplicationContext context = new AnnotationConfigApplicationContext(Application.class); // (1) Tomcat tomcatServer = context.getBean(Tomcat.class); tomcatServer.start(); System.out.println("Press ENTER to exit."); System.in.read(); }
@Override public void start() { try { tomcat.start(); } catch (LifecycleException e) { throw new RuntimeServiceException(e); } }
@Override protected void before() throws LifecycleException { this.tomcat = new Tomcat(); this.tomcat.getConnector().setPort(0); Context context = this.tomcat.addContext("/", null); this.tomcat.addServlet("/", "test", new TestServlet()); context.addServletMappingDecoded("/", "test"); this.tomcat.addServlet("/", "set-cookie", new CookiesServlet()); context.addServletMappingDecoded("/set-cookie", "set-cookie"); this.tomcat.start(); this.port = this.tomcat.getConnector().getLocalPort(); }
tomcat.start(); } catch (LifecycleException e) { throw new RuntimeException(e);