Hi Achim, we want to migrate an existing web application to an OSGi platform. Some of our clients host the application by themselves. They have their own infrastructure for web applications and strong environmental requirements. That's why we think it is much better to end up with simple war which runs on our client's preferred application server.
Out of your answer I read, it is not as simple I supposed it is to embed Karaf into tomcat? @all: Can anybody help me to understand why the class loading delegation does not work? The missing class is in a java.*package. From what I learned, this should be delegated to the parent class loader. Regards Hans-Arno Von: Achim Nierbeck [mailto:[email protected]] Gesendet: Dienstag, 28. Juni 2016 12:32 An: [email protected] Betreff: Re: Embedding Karaf 4.0.5 in web app - NoClassDefFoundError on startup Hi Milen and others whom it may concern ;) ... the biggest drawback is still how to run from ServletConextListener. AFAIK the felix Servlet Bridge is the only one available right now, though we do have some Work-InProgress for Pax-Web. If you ask Serge Huber, he might be able to give you some more feedback about the pain he went through. It's the reason he started contributing a Servlet Bridge to Pax-Web which is still work in progress. Involvement is highly appreciated ;) In general I still favor the other way round ... but I guess for certain migrational paths it might be a viable solution. regards, Achim 2016-06-28 12:18 GMT+02:00 Milen Dyankov <[email protected]<mailto:[email protected]>>: Achim, doing something similar is on my todo list (please don't ask why) so if there is any issue with embedding Karaf in web app I'm as well very interested to get it solved. Best, Milen On Tue, Jun 28, 2016 at 12:11 PM, Achim Nierbeck <[email protected]<mailto:[email protected]>> wrote: > Hi, > > why not the other way round? > Just run your webapplication inside Karaf, that's what Karaf is build for. > It's like you're trying to start a JBoss inside your Tomcat, why would > anyone do that :) > > regards, Achim > > > > > > 2016-06-28 12:06 GMT+02:00 slarti70 > <[email protected]<mailto:[email protected]>>: >> >> Hi, >> >> I am trying to start Karaf embedded in a Webapp using Tomcat 8.0.35 and >> Java >> 1.7.0_79. >> The Startup is done using a ServletContextListener, which simply creates a >> Main instance and calls launch() method. >> >> Main main = new Main( new String[ 0 ] ); >> try { >> main.launch(); >> this.framework = main.getFramework(); >> } catch ( Exception e ) { >> main = null; >> e.printStackTrace(); >> // logger.error( "Error starting Karaf", e ); >> } >> >> The startup bundles defined in startup.properties are the same as in the >> 4.0.5 distribution, which perfectly starts up standalone: >> >> # Bundles to be started on startup, with startlevel >> mvn\:org.apache.sshd/sshd-core/0.14.0 = 20 >> mvn\:org.apache.felix/org.apache.felix.metatype/1.1.2 = 5 >> mvn\:org.apache.karaf.services/org.apache.karaf.services.eventadmin/4.0.5 >> = >> 5 >> mvn\:org.ops4j.pax.url/pax-url-aether/2.4.7 = 5 >> mvn\:org.ops4j.pax.logging/pax-logging-api/1.8.5 = 8 >> mvn\:org.ops4j.pax.logging/pax-logging-service/1.8.5 = 8 >> mvn\:org.apache.felix/org.apache.felix.configadmin/1.8.8 = 10 >> mvn\:org.apache.felix/org.apache.felix.fileinstall/3.5.4 = 11 >> mvn\:org.apache.karaf.features/org.apache.karaf.features.core/4.0.5 = 15 >> >> >> The error on startup is the following: >> Exception in thread "FelixStartLevel" java.lang.NoClassDefFoundError: >> java/util/logging/LogRecord >> at >> >> org.ops4j.pax.logging.service.internal.JdkHandler.publish(JdkHandler.java:82) >> at java.util.logging.Logger.log(Logger.java:616) >> at java.util.logging.Logger.doLog(Logger.java:641) >> at java.util.logging.Logger.logp(Logger.java:757) >> at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:180) >> at >> org.apache.juli.logging.DirectJDKLog.debug(DirectJDKLog.java:103) >> at >> >> org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1174) >> at java.lang.ClassLoader.loadClass(ClassLoader.java:412) >> at java.lang.ClassLoader.loadClass(ClassLoader.java:358) >> at org.apache.felix.framework.Logger.doLog(Logger.java:89) >> at org.apache.felix.framework.Logger._log(Logger.java:118) >> at org.apache.felix.framework.Logger.log(Logger.java:62) >> at >> org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1376) >> at >> >> org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308) >> at java.lang.Thread.run(Thread.java:745) >> >> The complete log is attached here: >> startup_log.txt >> <http://karaf.922171.n3.nabble.com/file/n4046969/startup_log.txt> >> >> Can anybody help to understand, why the WebappClassLoader does not >> delegate >> to the JRE classes for the boot bundles? >> >> Workaround trials: >> I have found out, that the responsible bundles are the two >> org.ops4j.pax.logging bundles. I tried to use slf4j/log4j bundles instead >> and added felix.log to meet the requirements of felix.metatype: >> # mvn\:org.ops4j.pax.logging/pax-logging-api/1.8.5 = 8 >> # mvn\:org.ops4j.pax.logging/pax-logging-service/1.8.5 = 8 >> mvn\:org.slf4j/slf4j.log4j12/1.7.21 = 8 >> mvn\:org.slf4j/slf4j.api/1.7.21 = 8 >> mvn\:org.apache.log4j/log4j/1.2.17 = 8 >> mvn\:org.apache.felix/org.apache.felix.log/1.0.1 = 8 >> >> This starts up all boot bundles, but leads to a not even less strange >> exception when installing the boot features: >> >> 2016-06-28 11:57:39,083 [7-thread-1] WARN >> org.apache.karaf.features.internal.osgi.Activator () - Error >> starting activator >> java.lang.IllegalStateException: Invalid BundleContext. >> at >> >> org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:511) >> at >> >> org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:328) >> at >> >> org.apache.karaf.util.tracker.BaseActivator.registerMBean(BaseActivator.java:290) >> at >> >> org.apache.karaf.features.internal.osgi.Activator.doStart(Activator.java:264) >> at >> org.apache.karaf.util.tracker.BaseActivator.run(BaseActivator.java:233) >> at >> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) >> at java.util.concurrent.FutureTask.run(FutureTask.java:262) >> at >> >> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) >> at >> >> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) >> at java.lang.Thread.run(Thread.java:745) >> >> Log attached: >> startup_log2.txt >> <http://karaf.922171.n3.nabble.com/file/n4046969/startup_log2.txt> >> >> Any help would be appreciated. >> >> Hans-Arno >> >> P.S.: I am a OSGi/Karaf newbee >> >> >> >> >> -- >> View this message in context: >> http://karaf.922171.n3.nabble.com/Embedding-Karaf-4-0-5-in-web-app-NoClassDefFoundError-on-startup-tp4046969.html >> Sent from the Karaf - User mailing list archive at Nabble.com. > > > > > -- > > Apache Member > Apache Karaf <http://karaf.apache.org/> Committer & PMC > OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & > Project Lead > blog <http://notizblog.nierbeck.de/> > Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> > > Software Architect / Project Manager / Scrum Master > -- http://about.me/milen -- Apache Member Apache Karaf <http://karaf.apache.org/> Committer & PMC OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & Project Lead blog <http://notizblog.nierbeck.de/> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> Software Architect / Project Manager / Scrum Master
