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

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

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

Tomcat.setPort介绍

[英]Set the port for the default connector. Must be called before start().
[中]设置默认连接器的端口。必须在start()之前调用。

代码示例

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

tomcat = new Tomcat();
tomcat.setBaseDir(baseDir);
tomcat.setPort(url.getPort());
tomcat.getConnector().setProperty(
    "maxThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));

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

tomcat = new Tomcat();
tomcat.setBaseDir(baseDir);
tomcat.setPort(url.getPort());
tomcat.getConnector().setProperty(
    "maxThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));

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

tomcat.setPort(0);
tomcat.setBaseDir(path);
Context ctx = tomcat.addContext("", path);

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

tomcat.setPort(0);
tomcat.setBaseDir(path);
Context ctx = tomcat.addContext("", path);

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

private void enablePlainConnector(Tomcat tomcat) {
  log.info("Using http protocol");
  tomcat.setPort(getSettings().getPort());
}

代码示例来源: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: org.crazyyak.embedded/yak-embedded-tomcat

private void configureDefaultConnector(int port, int securePort) {
 System.out.println("Creating default connector on port " + port);
 tomcat.setPort(port);
 if (securePort > 0) {
  tomcat.getConnector().setRedirectPort(securePort);
 }
}

代码示例来源:origin: org.brutusin/rpc-tomcat

protected Tomcat createTomcat(Integer port) throws IOException {
  port = getPort(port);
  System.setProperty("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE", "true");
  Tomcat tomcat = new Tomcat();
  Path tempPath = Files.createTempDirectory("brutusin-rcp-tests");
  tomcat.setBaseDir(tempPath.toString());
  tomcat.setPort(port);
  return tomcat;
}

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

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

代码示例来源:origin: org.dbflute.tomcat/tomcat-boot

protected void prepareServer() {
  server = createTomcat();
  server.setPort(port);
  if (baseDir != null) {
    server.setBaseDir(baseDir);
  }
  adjustServer();
  setupWebappContext();
  setupServerConfigIfNeeds();
}

代码示例来源:origin: poutsma/web-function-sample

public void startTomcatServer() throws LifecycleException {
  RouterFunction<?> route = routingFunction();
  HttpHandler httpHandler = toHttpHandler(route);
  Tomcat tomcatServer = new Tomcat();
  tomcatServer.setHostname(HOST);
  tomcatServer.setPort(PORT);
  Context rootContext = tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
  ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
  Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
  rootContext.addServletMapping("/", "httpHandlerServlet");
  tomcatServer.start();
}

代码示例来源:origin: com.github.mjeanroy/junit-servers-tomcat

private Tomcat initServer() {
  Tomcat tomcat = new Tomcat();
  tomcat.setBaseDir(configuration.getBaseDir());
  tomcat.setPort(configuration.getPort());
  tomcat.getHost().setAutoDeploy(true);
  tomcat.getHost().setDeployOnStartup(true);
  if (configuration.isEnableNaming()) {
    tomcat.enableNaming();
  }
  return tomcat;
}

相关文章