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

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

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

Tomcat.addWebapp介绍

[英]This is equivalent to adding a web application to Tomcat's webapps directory. The equivalent of the default web.xml will be applied to the web application and any WEB-INF/web.xml and META-INF/context.xml packaged with the application will be processed normally. Normal web fragment and javax.servlet.ServletContainerInitializer processing will be applied.
[中]这相当于将一个web应用程序添加到Tomcat的webapps目录。相当于默认web。xml将应用于web应用程序和任何web-INF/web。xml和META-INF/context。与应用程序打包的xml将正常处理。普通的web片段和javax。servlet。将应用ServletContainerInitializer处理。

代码示例

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

@Before
public void setUp() throws Exception {
 props.setProperty(Property.PATH_DATA.getKey(), temp.newFolder("data").getAbsolutePath());
 when(tomcat.addWebapp(anyString(), anyString())).thenReturn(mock(StandardContext.class));
}

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

@Test
public void configure_root_webapp() throws Exception {
 props.setProperty("foo", "bar");
 StandardContext context = mock(StandardContext.class);
 when(tomcat.addWebapp(anyString(), anyString())).thenReturn(context);
 underTest.configure(tomcat, new Props(props));
 // configure webapp with properties
 verify(context).addParameter("foo", "bar");
}

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

@Test
public void create_dir_and_configure_static_directory() throws Exception {
 File dir = temp.newFolder();
 dir.delete();
 underTest.addStaticDir(tomcat, "/deploy", dir);
 assertThat(dir).isDirectory().exists();
 verify(tomcat).addWebapp("/deploy", dir.getAbsolutePath());
}

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

private static StandardContext addContext(Tomcat tomcat, String contextPath, File dir) {
 try {
  StandardContext context = (StandardContext) tomcat.addWebapp(contextPath, dir.getAbsolutePath());
  context.setClearReferencesHttpClientKeepAliveThread(false);
  context.setClearReferencesStopThreads(false);
  context.setClearReferencesStopTimerThreads(false);
  context.setClearReferencesStopTimerThreads(false);
  context.setAntiResourceLocking(false);
  context.setReloadable(false);
  context.setUseHttpOnly(true);
  context.setTldValidation(false);
  context.setXmlValidation(false);
  context.setXmlNamespaceAware(false);
  context.setUseNaming(false);
  context.setDelegate(true);
  context.setJarScanner(new NullJarScanner());
  context.setAllowCasualMultipartParsing(true);
  context.setCookies(false);
  // disable JSP and WebSocket support
  context.setContainerSciFilter("org.apache.tomcat.websocket.server.WsSci|org.apache.jasper.servlet.JasperInitializer");
  return context;
 } catch (ServletException e) {
  throw new IllegalStateException("Fail to configure webapp from " + dir, e);
 }
}

代码示例来源: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: codefollower/Tomcat-Research

/**
 * @see #addWebapp(String, String)
 */
public Context addWebapp(Host host, String url, String path) {
  return addWebapp(host, url, url, path);
}

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

/** 
 * Add a webapp using normal WEB-INF/web.xml if found.
 * 
 * @param contextPath
 * @param baseDir
 * @return new Context
 * @throws ServletException 
 */
public Context addWebapp(String contextPath, 
                 String baseDir) throws ServletException {
  
  return addWebapp(getHost(), contextPath, baseDir);    
}

代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9

/** 
 * Add a webapp using normal WEB-INF/web.xml if found.
 * 
 * @param contextPath
 * @param baseDir
 * @return new Context
 * @throws ServletException 
 */
public Context addWebapp(String contextPath, 
                 String baseDir) throws ServletException {
  
  return addWebapp(getHost(), contextPath, baseDir);    
}

代码示例来源:origin: com.ovea.tajin.server/tajin-server-tomcat7

/** 
 * Add a webapp using normal WEB-INF/web.xml if found.
 * 
 * @param contextPath
 * @param baseDir
 * @return new Context
 * @throws ServletException 
 */
public Context addWebapp(String contextPath, 
                 String baseDir) throws ServletException {
  
  return addWebapp(getHost(), contextPath, baseDir);    
}

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

/** 
 * Add a webapp using normal WEB-INF/web.xml if found.
 * 
 * @param contextPath
 * @param baseDir
 * @return new Context
 * @throws ServletException 
 */
public Context addWebapp(String contextPath, 
                 String baseDir) throws ServletException {
  
  return addWebapp(getHost(), contextPath, baseDir);    
}

代码示例来源:origin: org.apache.catalina/com.springsource.org.apache.catalina

/** 
 * Add a webapp using normal WEB-INF/web.xml if found.
 * 
 * @param contextPath
 * @param baseDir
 * @return new Context
 * @throws ServletException 
 */
public Context addWebapp(String contextPath, 
                 String baseDir) throws ServletException {
  
  return addWebapp(getHost(), contextPath, baseDir);    
}

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

protected void doSetupWebappContextWebappDir() throws ServletException {
  final String webappPath = prepareWebappPath();
  final String docBase = new File(webappPath).getAbsolutePath();
  final Context context = server.addWebapp(contextPath, docBase);
  final String webXmlPath = prepareWebXmlPath(webappPath);
  context.getServletContext().setAttribute(Globals.ALT_DD_ATTR, webXmlPath);
}

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

protected void doSetupWebappContextWar(String warPath) throws ServletException {
  server.addWebapp(contextPath, warPath);
  if (!isUnpackWARsDisabled()) {
    prepareUnpackWARsEnv();
  }
}

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

tomcat.addWebapp(tomcat.getHost(), contextPath, webAppPath);

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

public class MyServer {

public static void main(String[] args) throws Exception {
  Tomcat tomcat = new Tomcat();
  tomcat.setPort(8080);

  tomcat.addWebapp("","webapp"); 

  tomcat.start();
  tomcat.getServer().await();
  }

 }

代码示例来源:origin: restx/restx

public TomcatWebServer(String appBase, int port, String bindInterface) throws ServletException {
  super(checkNotNull(appBase), port, bindInterface, "Apache Tomcat", "org.apache.tomcat", "tomcat-catalina");
  tomcat = new Tomcat();
  tomcat.setPort(port);
  tomcat.setBaseDir(".");
  tomcat.getHost().setAppBase(".");
  String contextPath = "/";
  // Add AprLifecycleListener
  StandardServer server = (StandardServer) tomcat.getServer();
  AprLifecycleListener listener = new AprLifecycleListener();
  server.addLifecycleListener(listener);
  context = tomcat.addWebapp(contextPath, appBase);
}

相关文章