public void contextInitialized(ServletContextEvent event) {
// Create the runtime
ServletContext servletContext = event.getServletContext();
ServletContextPropertiesProvider propsProvider = new ServletContextPropertiesProvider(servletContext);
Runtime runtime = RuntimeLocator.createRuntime(new TomcatRuntimeFactory(servletContext), propsProvider);
runtime.init();
// Register the {@link RuntimeEnvironment}, {@link ResourceInstaller} services
registerServices(servletContext, runtime);
// Install and start this webapp as a module
WebAppContextListener webappInstaller = new WebAppContextListener();
Module module = webappInstaller.installWebappModule(servletContext);
servletContext.setAttribute(Module.class.getName(), module);
try {
module.start();
} catch (ModuleException ex) {
throw new IllegalStateException(ex);
}
// HttpService integration
Module sysmodule = runtime.getModuleContext().getModule();
BundleContext bundleContext = sysmodule.adapt(Bundle.class).getBundleContext();
servletContext.setAttribute(BundleContext.class.getName(), bundleContext);
}