}
return count;
}
private StandardContext startWebApp(Host host) throws Exception {
StandardContext context = new StandardContext();
try {
context.setPath(contextRoot);
context.addLifecycleListener(new ContextConfig());
File docBase = new File(serverTempDir, contextRoot);
if (!docBase.exists()) {
docBase.mkdirs();
}
context.setDocBase(docBase.getPath());
final Loader loader = new WebCtxLoader(classloader);
loader.setContainer(host);
context.setLoader(loader);
context.setInstanceManager(new LocalInstanceManager());
final int j = servletClass.indexOf(".");
final String servletName = j < 0 ? servletClass : servletClass.substring(j + 1);
final Class<?> clazz = classloader.loadClass(servletClass);
final Wrapper wsfsWrapper = context.createWrapper();
wsfsWrapper.setName(servletName);
wsfsWrapper.setServlet((Servlet) clazz.newInstance());
wsfsWrapper.setServletClass(servletClass);
context.addChild(wsfsWrapper);
context.addServletMapping(urlPattern, servletName);
host.addChild(context);
context.create();
} catch (Exception e) {
throw MESSAGES.createContextPhaseFailed(e);
}
try {
context.start();
} catch (LifecycleException e) {
throw MESSAGES.startContextPhaseFailed(e);
}
return context;
}