Search code examples
osgiapache-karafapache-servicemix

NoClassDefFoundError in ServiceMix / Karaf


I've created a Karaf Archive with several bundles inside. When deploying this archive in ServiceMix, I can confirm that every bundles are correctly installed (their status are on Active). Nevertheless, when using it, a NoClassDefFoundError is thrown :

org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[ID-0363932-55444-1456402276950-1-78][org.apache.camel.component.file.GenericFileMessage@15b10bce]
    at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1658)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.impl.DefaultExchange.setException(DefaultExchange.java:345)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:254)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:177)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:442)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:214)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:178)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)[199:org.apache.camel.camel-core:2.16.1]
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)[199:org.apache.camel.camel-core:2.16.1]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_67]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)[:1.7.0_67]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)[:1.7.0_67]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)[:1.7.0_67]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_67]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_67]
    at java.lang.Thread.run(Thread.java:745)[:1.7.0_67]
Caused by: java.lang.NoClassDefFoundError: org/jdom2/xpath/jaxen/JaxenCompiled
    at org.jdom2.xpath.jaxen.JaxenXPathFactory.compile(JaxenXPathFactory.java:82)[260:wrap_mvn_org.jdom_jdom2_2.0.4:0.0.0]

Which I don't understand... Because when executing this command in Karaf console : bundle:classes <jdom2BundleId>, I get :

...
org/jdom2/xpath/jaxen/JaxenCompiled.class
...

Here is a snippet of the pom.xml from the bundle using Jdom2 bundle :

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.5.4</version>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Import-Package>
                *
            </Import-Package>
            <Export-Package>
                my.package.*
            </Export-Package>
        </instructions>
    </configuration>

<dependency>
    <groupId>org.jdom</groupId>
    <artifactId>jdom2</artifactId>
    <version>2.0.4</version>
</dependency>

Here is the result of the command feature:info <deployedKarafArchiveName>

Description:
  the description
Feature has no configuration
Feature has no configuration files
Feature has no dependencies.
Feature contains followed bundles:
  mvn:org.apache.camel/camel-context/2.16.1
  mvn:com.sun.xml.bind/jaxb-core/2.2.11
  mvn:org.apache.camel/camel-core/2.16.1
  mvn:commons-io/commons-io/2.4
  wrap:mvn:generic/generic-common/1.2.9
  wrap:mvn:org.jdom/jdom2/2.0.4
  mvn:commons-codec/commons-codec/1.7
  mvn:org.slf4j/slf4j-api/1.7.12
  mvn:org.slf4j/slf4j-log4j12/1.7.7
Feature has no conditionals.

Solution

  • Your feature is not correct. You need the following dependency :

    <dependency>
      <groupId>jaxen</groupId>
      <artifactId>jaxen</artifactId>
      <version>1.1.3</version>
    </dependency>
    

    It's marked as optional in the org.jdom/jdom2, but needed by JaxenCompiled

    I suppose your stacktrace is not complete, and you have "caused by" statements about classes in "org.jaxen".