Java Code Examples for org.apache.catalina.Context#setConfigFile()
The following examples show how to use
org.apache.catalina.Context#setConfigFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Tomcat.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * @see #addWebapp(String, String) * * @param name Ignored. The contextPath will be used * * @deprecated Use {@link #addWebapp(Host, String, String)} */ @Deprecated public Context addWebapp(Host host, String contextPath, String name, String docBase) { silence(host, contextPath); Context ctx = createContext(host, contextPath); ctx.setPath(contextPath); ctx.setDocBase(docBase); ctx.addLifecycleListener(new DefaultWebXmlListener()); ctx.setConfigFile(getWebappConfigFile(docBase, contextPath)); ContextConfig ctxCfg = new ContextConfig(); ctx.addLifecycleListener(ctxCfg); // prevent it from looking ( if it finds one - it'll have dup error ) ctxCfg.setDefaultWebXml(noDefaultWebXmlPath()); if (host == null) { getHost().addChild(ctx); } else { host.addChild(ctx); } return ctx; }
Example 2
Source File: Tomcat.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * @see #addWebapp(String, String) * * @param name Ignored. The contextPath will be used * * @deprecated Use {@link #addWebapp(Host, String, String)} */ @Deprecated public Context addWebapp(Host host, String contextPath, String name, String docBase) { silence(host, contextPath); Context ctx = createContext(host, contextPath); ctx.setPath(contextPath); ctx.setDocBase(docBase); ctx.addLifecycleListener(new DefaultWebXmlListener()); ctx.setConfigFile(getWebappConfigFile(docBase, contextPath)); ContextConfig ctxCfg = new ContextConfig(); ctx.addLifecycleListener(ctxCfg); // prevent it from looking ( if it finds one - it'll have dup error ) ctxCfg.setDefaultWebXml(noDefaultWebXmlPath()); if (host == null) { getHost().addChild(ctx); } else { host.addChild(ctx); } return ctx; }
Example 3
Source File: RpsMain.java From rock-paper-scissors-in-java with MIT License | 6 votes |
public static void main(String[] args) throws Exception, LifecycleException { // Define a folder to hold web application contents. String webappDirLocation = "src/main/webapp/"; Tomcat tomcat = new Tomcat(); // Define port number for the web application String webPort = System.getenv("PORT"); if (webPort == null || webPort.isEmpty()) { webPort = "8080"; } // Bind the port to Tomcat server tomcat.setPort(Integer.valueOf(webPort)); // Define a web application context. Context context = tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath()); // Define and bind web.xml file location. File configFile = new File(webappDirLocation + "WEB-INF/web.xml"); context.setConfigFile(configFile.toURI().toURL()); tomcat.start(); logger.info("Server started at http://localhost:{}", webPort); tomcat.getServer().await(); }
Example 4
Source File: Tomcat.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * @param host The host in which the context will be deployed * @param contextPath The context mapping to use, "" for root context. * @param docBase Base directory for the context, for static files. * Must exist, relative to the server home * @param config Custom context configurator helper * @return the deployed context * @see #addWebapp(String, String) */ public Context addWebapp(Host host, String contextPath, String docBase, LifecycleListener config) { silence(host, contextPath); Context ctx = createContext(host, contextPath); ctx.setPath(contextPath); ctx.setDocBase(docBase); ctx.addLifecycleListener(getDefaultWebXmlListener()); ctx.setConfigFile(getWebappConfigFile(docBase, contextPath)); ctx.addLifecycleListener(config); if (config instanceof ContextConfig) { // prevent it from looking ( if it finds one - it'll have dup error ) ((ContextConfig) config).setDefaultWebXml(noDefaultWebXmlPath()); } if (host == null) { getHost().addChild(ctx); } else { host.addChild(ctx); } return ctx; }
Example 5
Source File: HermesTomcat.java From hermes with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println("usage: java HermesTomcat webRoot port"); System.exit(1); } String webRoot = args[0]; String port = args[1]; HermesTomcat tomcat = new HermesTomcat(); System.out.println(String.format("Starting webapp %s at port %s", webRoot, port)); System.out.println(String.format("acceptCount %s", tomcat.acceptCount)); System.out.println(String.format("maxConnections %s", tomcat.maxConnections)); System.out.println(String.format("maxQueueSize %s", tomcat.maxQueueSize)); System.out.println(String.format("maxThreads %s", tomcat.maxThreads)); System.out.println(String.format("shutdownPort %s", tomcat.shutdownPort)); System.out.println(String.format("shutdownString %s", tomcat.shutdownString)); // Define a folder to hold web application contents. File webappDirLocation = new File(webRoot); // Bind the port to Tomcat server tomcat.setPort(Integer.valueOf(port)); // Define a web application context. Context context = tomcat.addWebapp("", webappDirLocation.getAbsolutePath()); // Define and bind web.xml file location. File configFile = new File(webappDirLocation, "/WEB-INF/web.xml"); context.setConfigFile(configFile.toURI().toURL()); tomcat.start(); tomcat.getServer().await(); tomcat.stop(); }
Example 6
Source File: StandardContextSF.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Store a Context as Separate file as configFile value from context exists. * filename can be relative to catalina.base. * * @see org.apache.catalina.storeconfig.IStoreFactory#store(java.io.PrintWriter, * int, java.lang.Object) */ @Override public void store(PrintWriter aWriter, int indent, Object aContext) throws Exception { if (aContext instanceof StandardContext) { StoreDescription desc = getRegistry().findDescription( aContext.getClass()); if (desc.isStoreSeparate()) { URL configFile = ((StandardContext) aContext) .getConfigFile(); if (configFile != null) { if (desc.isExternalAllowed()) { if (desc.isBackup()) storeWithBackup((StandardContext) aContext); else storeContextSeparate(aWriter, indent, (StandardContext) aContext); return; } } else if (desc.isExternalOnly()) { // Set a configFile so that the configuration is actually saved Context context = ((StandardContext) aContext); Host host = (Host) context.getParent(); File configBase = host.getConfigBaseFile(); ContextName cn = new ContextName(context.getName(), false); String baseName = cn.getBaseName(); File xml = new File(configBase, baseName + ".xml"); context.setConfigFile(xml.toURI().toURL()); if (desc.isBackup()) storeWithBackup((StandardContext) aContext); else storeContextSeparate(aWriter, indent, (StandardContext) aContext); return; } } } super.store(aWriter, indent, aContext); }