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

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

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

Tomcat.<init>介绍

暂无

代码示例

代码示例来源: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: 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: spring-projects/spring-framework

@Override
public void setup() {
  Connector connector = new Connector(Http11NioProtocol.class.getName());
  connector.setPort(0);
  File baseDir = createTempDir("tomcat");
  String baseDirPath = baseDir.getAbsolutePath();
  this.tomcatServer = new Tomcat();
  this.tomcatServer.setBaseDir(baseDirPath);
  this.tomcatServer.setPort(0);
  this.tomcatServer.getService().addConnector(connector);
  this.tomcatServer.setConnector(connector);
}

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

@Override
protected void initServer() throws Exception {
  this.tomcatServer = new Tomcat();
  this.tomcatServer.setBaseDir(baseDir);
  this.tomcatServer.setHostname(getHost());
  this.tomcatServer.setPort(getPort());
  ServletHttpHandlerAdapter servlet = initServletAdapter();
  File base = new File(System.getProperty("java.io.tmpdir"));
  Context rootContext = tomcatServer.addContext(this.contextPath, base.getAbsolutePath());
  Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet).setAsyncSupported(true);
  rootContext.addServletMappingDecoded(this.servletMapping, "httpHandlerServlet");
  if (wsListener != null) {
    rootContext.addApplicationListener(wsListener.getName());
  }
}

代码示例来源: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

DispatcherServlet.addHttpHandler(url.getPort(), handler);
String baseDir = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
tomcat = new Tomcat();
tomcat.setBaseDir(baseDir);
tomcat.setPort(url.getPort());

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

DispatcherServlet.addHttpHandler(url.getPort(), handler);
String baseDir = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
tomcat = new Tomcat();
tomcat.setBaseDir(baseDir);
tomcat.setPort(url.getPort());

代码示例来源: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: pippo-java/pippo

protected Tomcat createTomcat() {
  return new Tomcat();
}

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

tomcat = new Tomcat();
tomcat.setHostname("localhost");
tomcat.setPort(0);

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

@Override
public WebServer getWebServer(HttpHandler httpHandler) {
  Tomcat tomcat = new Tomcat();
  File baseDir = (this.baseDirectory != null) ? this.baseDirectory
      : createTempDir("tomcat");
  tomcat.setBaseDir(baseDir.getAbsolutePath());
  Connector connector = new Connector(this.protocol);
  tomcat.getService().addConnector(connector);
  customizeConnector(connector);
  tomcat.setConnector(connector);
  tomcat.getHost().setAutoDeploy(false);
  configureEngine(tomcat.getEngine());
  TomcatHttpHandlerAdapter servlet = new TomcatHttpHandlerAdapter(httpHandler);
  prepareContext(tomcat.getHost(), servlet);
  return new TomcatWebServer(tomcat, getPort() >= 0);
}

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

tomcat = new Tomcat();
tomcat.setHostname("localhost");
tomcat.setPort(0);

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

@Override
public WebServer getWebServer(ServletContextInitializer... initializers) {
  Tomcat tomcat = new Tomcat();
  File baseDir = (this.baseDirectory != null) ? this.baseDirectory
      : createTempDir("tomcat");
  tomcat.setBaseDir(baseDir.getAbsolutePath());
  Connector connector = new Connector(this.protocol);
  tomcat.getService().addConnector(connector);
  customizeConnector(connector);
  tomcat.setConnector(connector);
  tomcat.getHost().setAutoDeploy(false);
  configureEngine(tomcat.getEngine());
  for (Connector additionalConnector : this.additionalTomcatConnectors) {
    tomcat.getService().addConnector(additionalConnector);
  }
  prepareContext(tomcat.getHost(), initializers);
  return getTomcatWebServer(tomcat);
}

代码示例来源: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

public TomcatWebSocketTestServer(Class<?>... serverConfigs) {
  this.tomcatServer = new Tomcat();
  this.tomcatServer.setPort(0);
  this.tomcatServer.setBaseDir(createTempDir());
  this.serverContext = new AnnotationConfigWebApplicationContext();
  this.serverContext.register(serverConfigs);
  Context context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
  context.addApplicationListener(WsContextListener.class.getName());
  Tomcat.addServlet(context, "dispatcherServlet", new DispatcherServlet(this.serverContext))
      .setAsyncSupported(true);
  context.addServletMappingDecoded("/", "dispatcherServlet");
}

代码示例来源: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

int port = Integer.parseInt(serverProperties.getProperty(PORT_PROPERTY));
tomcat = new Tomcat();
tomcat.setPort(port);
tomcat.setBaseDir(getWorkingDir());

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

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

相关文章