org.apache.catalina.startup.Tomcat.start()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(170)

本文整理了Java中org.apache.catalina.startup.Tomcat.start()方法的一些代码示例,展示了Tomcat.start()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tomcat.start()方法的具体详情如下:
包路径:org.apache.catalina.startup.Tomcat
类名称:Tomcat
方法名:start

Tomcat.start介绍

[英]Start the server.
[中]启动服务器。

代码示例

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: apache/usergrid

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);
  }
}

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: spring-projects/spring-framework

@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());
    }
  });
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void startInternal() throws LifecycleException {
  this.tomcatServer.start();
  setPort(this.tomcatServer.getConnector().getLocalPort());
}

代码示例来源:origin: OryxProject/oryx

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;
}

代码示例来源:origin: oblac/jodd

@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();
}

代码示例来源:origin: apache/incubator-dubbo

tomcat.start();
} catch (LifecycleException e) {
  throw new IllegalStateException("Failed to start tomcat server at " + url.getAddress(), e);

代码示例来源:origin: apache/incubator-dubbo

tomcat.start();
} catch (LifecycleException e) {
  throw new IllegalStateException("Failed to start tomcat server at " + url.getAddress(), e);

代码示例来源:origin: org.springframework.boot/spring-boot

this.tomcat.start();

代码示例来源:origin: SonarSource/sonarqube

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);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

tomcat.start();
port1 = tomcat.getConnector().getLocalPort();

代码示例来源:origin: AsyncHttpClient/async-http-client

wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/*", "webdav");
tomcat.start();
port1 = tomcat.getConnector().getLocalPort();

代码示例来源:origin: line/armeria

@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));
  }
};

代码示例来源:origin: spring-projects/spring-integration

@Override
public void afterPropertiesSet() throws Exception {
  this.tomcatServer.start();
}

代码示例来源:origin: pippo-java/pippo

tomcat.start();
} catch (LifecycleException e) {
  log.error("Unable to launch Tomcat", e);

代码示例来源:origin: hantsy/spring-reactive-sample

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();
}

代码示例来源:origin: org.nuxeo.runtime/nuxeo-runtime-server

@Override
public void start() {
  try {
    tomcat.start();
  } catch (LifecycleException e) {
    throw new RuntimeServiceException(e);
  }
}

代码示例来源:origin: spring-projects/spring-restdocs

@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();
}

代码示例来源:origin: camunda/camunda-bpm-platform

tomcat.start();
} catch (LifecycleException e) {
 throw new RuntimeException(e);

相关文章