String fullPath = context.getName() + path; // this is the problem. Host must not be null String hostName = context.getParent().getName(); The last line shows clearly that a context must have a parent (a host) if it is to be configured by a ContextConfig. You will learn how the web.xml file is parsed in Chapter 15, "Digester". In short, you must have a host unless you write your own ContextConfig class.
Application 1 The first application in this chapter demonstrates the use of a host as the top level container. This application uses two classes, ex13.pyrmont.core.SimpleContextConfig and ex13.pyrmont.startup.Bootstrap1 class. The SimpleContextConfig class is copied from Chapter 11 and the Bootstrap2 class is given in Listing 13.5: Listing 13.5: The Bootstrap1 Class
package ex13.pyrmont.startup; import import import import import import import import import import import import import
ex13.pyrmont.core.SimpleContextConfig; org.apache.catalina.Connector; org.apache.catalina.Context; org.apache.catalina.Host; org.apache.catalina.Lifecycle; org.apache.catalina.LifecycleListener; org.apache.catalina.Loader; org.apache.catalina.Wrapper; org.apache.catalina.connector.http.HttpConnector; org.apache.catalina.core.StandardContext; org.apache.catalina.core.StandardHost; org.apache.catalina.core.StandardWrapper; org.apache.catalina.loader.WebappLoader;
public final class Bootstrap1 { public static void main(String[] args) { System.setProperty("catalina.base", System.getProperty("user.dir")); Connector connector = new HttpConnector(); Wrapper wrapper1 = new StandardWrapper(); wrapper1.setName("Primitive"); wrapper1.setServletClass("PrimitiveServlet"); Wrapper wrapper2 = new StandardWrapper();