apache karaf 中的 ClassNotFoundException 错误

ClassNotFoundException error in apache karaf

我在 web.xml 文件中添加了 contect-param 选项卡

<context-param>
    <param-name>blueprintLocation</param-name>
    <param-value>OSGI-INF/blueprint/blueprint.xml</param-value>
</context-param>

还有 listner class 在 web.xml 文件中

<listener>
    <listener-class>org.apache.aries.blueprint.web.BlueprintContextListener</listener-class>
</listener>

加载到 karaf 后,出现以下错误:

java.lang.ClassNotFoundException: org.apache.aries.blueprint.web.BlueprintContextListener not found by com.test.test.core.jsonstore-http-api

如何解决这个问题?

错误表明您的包可能没有在他的 MANIFEST.MF 文件中导入包 org.apache.aries.blueprint.web

有几种方法可以解决这个问题,如果您使用 maven-bundle-plugin,您可以手动将包添加到 Import-Package 指令,就像这样:

<plugins>
  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
      <instructions>
        <Import-Package>
        org.apache.aries.blueprint.web,
        *
        </Import-Package>
      </instructions>
    </configuration>
  </plugin>
</plugins>

如果您使用其他工具生成清单,它应该与此类似。