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

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

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

Tomcat.init介绍

[英]Initialise the server.
[中]

代码示例

代码示例来源:origin: com.github.vatbub/awsec2wakelauncher.common

public static void startServer(int tomcatPort, String contextPath, String servletName, Servlet servlet, String servletPattern) throws LifecycleException, IOException {
  List<String> relativeFolders = new ArrayList<>();
  relativeFolders.add("src");
  relativeFolders.add("main");
  relativeFolders.add("webapp");
  tomcat = new Tomcat();
  tomcat.setBaseDir(".");
  tomcat.setPort(tomcatPort);
  // copy src/main/webapp to webapps/src/main/webapp
  baseDir = tomcat.getServer().getCatalinaHome().toPath();
  Path sourcePath = baseDir.getParent().resolve("server");
  webappsPath = baseDir.resolve("webapps");
  destinationPath = webappsPath;
  for (String folder : relativeFolders) {
    sourcePath = sourcePath.resolve(folder);
    destinationPath = destinationPath.resolve(folder);
  }
  FileUtils.copyDirectory(sourcePath.toFile(), destinationPath.toFile());
  Path relativePath = webappsPath.relativize(destinationPath);
  /* There needs to be a symlink to the current dir named 'webapps' */
  context = tomcat.addContext(contextPath, relativePath.toString());
  tomcat.addServlet(contextPath, servletName, servlet);
  context.addServletMappingDecoded(servletPattern, servletName);
  tomcat.init();
  tomcat.start();
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

tomcat.init(new ConfigurationSource() {
  protected final File userDir = new File(System.getProperty("user.dir"));
  protected final URI userDirUri = userDir.toURI();

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

import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.junit.AfterClass;
import org.junit.BeforeClass;

public class TomcatIntegrationTest {
 private static Tomcat t;
 private static final int TOMCAT_PORT = 9999;

 @BeforeClass
 public static void setUp() throws LifecycleException {
  t = new Tomcat();
  t.setBaseDir(".");
  t.setPort(TOMCAT_PORT);
  /* There needs to be a symlink to the current dir named 'webapps' */
  t.addWebapp("/service", "src/main/webapp"); 
  t.init();
  t.start();
 }

 @AfterClass
 public static void shutDownTomcat() throws LifecycleException {
  t.stop();
 }
}

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

tomcat.init();
  addListeners();
} catch (LifecycleException e) {

相关文章