We boot Karaf on the Servlet Context Listener chain. Regular Karaf Main class with a lot of special code to handle write access issues to the installation directory. We also support multiple instances from the same install so the caches are segmented and port conflicts resolved prior to startup (this is being refactored now): https://github.com/pentaho/pentaho-platform/blob/master/extensions/src/org/pentaho/platform/osgi/KarafBoot.java
Many of the classes are still in the WAR so we have added support for package wild-cards to system.packages.extra just make make it maintainable. Those wildcards are expanded out on boot resolving all packages available in the parent classloader ( war/WEB-INF/lib, JBoss module support as well): https://github.com/pentaho/pentaho-platform/blob/master/extensions/src/org/pentaho/platform/osgi/SystemPackageExtrapolator.java We bridge the HTTP service in OSGI out to the Servlet Container using the Felix HTTP Bridge Proxy Servlet: http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html I know JBoss and Apache Sling both do something very similar if you're looking for an out of the box solution -Nick From: Tom Barber <[email protected]<mailto:[email protected]>> Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> Date: Wednesday, March 23, 2016 at 7:58 AM To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> Subject: Re: Embedding Karaf in a WAR (Tomcat) Hi Martin I'm not sure quite how they bootstrap it, but Pentaho BI Server 6.x runs Tomcat & Karaf as a single service. Tom On Wed, Mar 23, 2016 at 11:53 AM, mjelen <[email protected]<mailto:[email protected]>> wrote: Dear Karaf developers und fellow users, due to customer requirements, we have to deliver all our software as web archives that are deployable on Tomcat. I'm hoping for this requirement to change in the future and I've been reasoning with our customer for over a year now about it, but at the moment they won't budge. We're currently developing a couple of web applications using Karaf and for production deployment, we have built a reasonably generic Felix WAR that starts the OSGi Container and includes the Felix File Install to read and start our application bundles from a custom directory. This approach has been working within Tomcat for over a year, but it has several drawbacks. Those that I'm aware of are: - The development and production environment are different from each other, introducing a new bug source (I can live with the necessary difference between embedded Jetty and bridged Tomcat, but I don't want more than that). - In production, we lose a lot of Karaf's features (such as the console, "feature"s, wrappers, KARs) and have to fall back on the basic File Install (no start levels etc.) and have to package the applications differently for development/production. - We have to maintain our custom Felix WAR distribution. To solve these problems, I would ideally have a generic Karaf launcher packaged as a WAR with the path to a Karaf home directory a parameter. That way I could simply decide whether Karaf gets started by the shell script or from my web application WAR. However, I can see several hurdles on the way and would be interested to hear if anyone has successfully done this before. Things I'm unsure of right now: - The default Karaf launcher (.bat/.sh scripts) uses the "endorsed libraries" mechanism of the JRE to override even classes like java.lang.Exception. Even if that works with current Tomcat versions (I haven't tried that yet), it seems fragile for the future in the embedded scenario and I'm not happy about changing Tomcat's libraries to that extent. - Will I have to include any/many libraries in Tomcat's classloader (e.g. in my WAR's WEB-INF/lib and modified framework.properties)? I already had to do that for my Felix WAR with Geronimo JTA-spec and it works fine at the moment, but again it makes me nervous regarding future enhancements. Any help will be appreciated, whether you have a few pointers for a solution, some code to share or even a horror story about how it can't be done :-). Kind regards -- Martin Jelen ISB AG -- View this message in context: http://karaf.922171.n3.nabble.com/Embedding-Karaf-in-a-WAR-Tomcat-tp4045931.html Sent from the Karaf - User mailing list archive at Nabble.com.
