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

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

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

Tomcat.setBaseDir介绍

[英]Tomcat needs a directory for temp files. This should be the first method called. By default, if this method is not called, we use: - system properties - catalina.base, catalina.home - $PWD/tomcat.$PORT (/tmp doesn't seem a good choice for security). TODO: disable work dir if not needed ( no jsp, etc ).
[中]Tomcat需要一个临时文件目录。这应该是第一个调用的方法。默认情况下,如果未调用此方法,我们将使用:-系统属性-catalina。基地,卡塔琳娜。首页-$PWD/tomcat$端口(/tmp似乎不是安全性的好选择)。TODO:如果不需要,禁用工作目录(无jsp等)。

代码示例

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

private void configureTomcat(Tomcat tomcat, Connector connector) {
 tomcat.setBaseDir(noSuchBaseDir.toAbsolutePath().toString());
 tomcat.setConnector(connector);
}

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

String baseDir = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
tomcat = new Tomcat();
tomcat.setBaseDir(baseDir);
tomcat.setPort(url.getPort());
tomcat.getConnector().setProperty(

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

String baseDir = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
tomcat = new Tomcat();
tomcat.setBaseDir(baseDir);
tomcat.setPort(url.getPort());
tomcat.getConnector().setProperty(

代码示例来源: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.setHostname("localhost");
tomcat.setPort(0);
tomcat.setBaseDir(path);
Context ctx = tomcat.addContext("", path);

代码示例来源: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: 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: AsyncHttpClient/async-http-client

tomcat.setHostname("localhost");
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

tomcat.setBaseDir(getSettings().getBaseFolder());

代码示例来源: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.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.setBaseDir(getWorkingDir());

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

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

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

public class App {
  public static void main(String[] args) throws Exception {
    Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    tomcat.setBaseDir(Files.createTempDirectory("tomcat-basedir").toString());
    tomcat.addWebapp("/", Files.createTempDirectory("yourwebapp-doc-base").toString());
    tomcat.start();
    tomcat.getServer().await();
  }
}

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

相关文章