From the way I understand it, 3.0 servlet containers are supposed to scan the classpath for implementations of the ServletContainerInitializer interface (ie. springs). Subsequently this should call the onStartup method of WebApplicationInitializer implementations.
Great. Awesome.
Now I want to build a jar file that will startup an embedded 3.0 servlet container (jetty 8 or tomcat 7) and do just that. I see plenty of examples on how to build a war file to do so. But how do I do this programmatically?
If you don't want to build a .war file, you'll need call WebApplicationInitializer's onStartup(ServletContext) yourself. How you get the servlet context is going to be specific to the container you use.
In Tomcat:
Tomcat tomcat = new Tomcat();
// skipping a few steps
Context ctx = tomcat.addContext(contextPath, baseDir);
ServletContext sc = ctx.getServletContext();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With