Additionally I had issues with setting a base application and auto deploying war files in a directory.
Below is my solution to remove the JSPServlet before startup.
Path tomcatBase = appHome.resolve("web");
Files.createDirectories(tomcatBase);
tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir(tomcatBase.toString());
tomcat.getHost().setAppBase(tomcatBase.resolve("apps").toString());
tomcat.getHost().setAutoDeploy(true);
tomcat.getHost().setDeployOnStartup(true);
tomcat.getHost().addLifecycleListener(new HostConfig());
tomcat.getHost().setConfigClass(NoJSPServletContextConfig.class.getName());
tomcat.start();
...
// until https://github.com/apache/tomcat/pull/40 is addressed cannot
// subclass tomcat so remove JSP support directly.
public static class NoJSPServletContextConfig extends ContextConfig {
@Override
public void lifecycleEvent(LifecycleEvent event) {
if (Lifecycle.BEFORE_START_EVENT.equals(event.getType())) {
Context ctx = (Context) event.getLifecycle();
Tomcat.initWebappDefaults(ctx);
Container jspServlet = ctx.findChild("jsp");
if (jspServlet != null) {
for (String pattern : ctx.findServletMappings()) {
String servletName = ctx.findServletMapping(pattern);
if ("jsp".equals(servletName)) {
ctx.removeServletMapping(pattern);
}
}
ctx.removeChild(jspServlet);
}
}
super.lifecycleEvent(event);
}
}
No comments:
Post a Comment