ServiceMix / Karaf中的NoClassDefFoundError

时间:2016-02-25 14:48:14

标签: osgi apache-karaf apache-servicemix

我创建了一个带有几个捆绑包的Karaf档案库。 在ServiceMix中部署此存档时,我可以确认每个软件包都已正确安装(其状态为活动)。然而,在使用它时,会抛出NoClassDefFoundError

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]

我不明白...因为在Karaf控制台执行此命令时:bundle:classes <jdom2BundleId>,我得到:

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

以下是使用Jdom2捆绑包的 pom.xml 的摘录:

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

以下是命令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.

2 个答案:

答案 0 :(得分:2)

您的功能不正确。您需要以下依赖项:

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

它在org.jdom / jdom2中标记为可选,但JaxenCompiled需要

我认为你的堆栈跟踪是不完整的,并且你在“org.jaxen”中有关于类的语句“由”引起。

答案 1 :(得分:0)

您应该检查消费Bundle的Import-Package和提供Bundle的Export-Package。确保Package实际上是a)导出的,b)从相应的bundle导入。