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]> 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]>:
>>
>> 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

Reply via email to