Hi,

I worked with Serge (from Jahia) to embed Karaf in tomcat as a war.

It's available there:

https://github.com/apache/karaf/tree/master/demos/web

You will see that this war use a WebAppListener that starts Karaf in Tomcat.

Regards
JB

On 03/23/2016 12:53 PM, mjelen 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.


--
Jean-Baptiste Onofré
[email protected]
http://blog.nanthrax.net
Talend - http://www.talend.com

Reply via email to