【问题标题】:jar bundle and its classpath in ServiceMix-karafServiceMix-karaf 中的 jar 包及其类路径
【发布时间】:2012-04-12 14:16:15
【问题描述】:

我正在开发 2 个 jar 文件(jar1 和 jar2 - 2 个 jar 的 pom.xml 中的打包类型是 jar)并将它们安装到 serviceMix 中。 Jar1 将使用来自 jar2 的一些包。

在 manifest.mf 文件中,我使用了 jar1 和 jar2 的导入和导出。安装到 serviceMix 4.3.0 后。一切进展顺利。从 jar 1 开始,我可以使用 jar2 中的包(我通过调试代码知道这一点)。但是问题就在这里:

The structure of Jar2: 
  jar2:/ 
        . 
        com 
               abc 
                   .......(classes) 
        META-INF 
               MANIFEST.MF 
        FactoryContext.xml 

The short version of jar2's MANIFEST.MF is 
   Bundle-ClassPath: . 
   Bundle-Name: jar2 
   Bundle-SymbolicName: jar2 
   Bundle-Version: 1.0.0 
   Export-Package: com.abc 
   Import-Package: xyz 
   Tool: Bnd-1.50.0 

Jar1 调用 Jar2 的一个方法,该方法使用下面的语句

context = new ClassPathXmlApplicationContext("FactoryContext.xml");

每当它进入这个语句时,它总是抛出异常,说 FactoryContext.xml 不存在。 (我来宾这个文件不在类路径中)

你知道如何让它工作吗?

【问题讨论】:

  • 用更广泛的“osgi”标签重新标记,这不是特定于 Karaf/ServiceMix,您可能会获得更多视图。

标签: osgi bundle classpath apache-karaf apache-servicemix


【解决方案1】:

我还在 ServiceMix 论坛上发布了我的问题,我从 Freeman-2 得到了答案。 这是答案

You can try to put  FactoryContext.xml in a unique folder like META- 
INF/MyFactoryContext/FactoryContext.xml, then jar2 also export package   
META-INF.MyFactoryContext, and jar1 import package META- 
INF.MyFactoryContext, and  then should be able to use code like 
context = new ClassPathXmlApplicationContext("META-INF/ 
MyFactoryContext/FactoryContext.xml"); 
in jar1.

这是链接 http://servicemix.396122.n5.nabble.com/question-about-jar-bundle-and-classpath-td5602052.html

【讨论】:

    猜你喜欢
    • 2010-09-16
    • 2016-06-08
    • 2013-04-08
    • 2011-10-19
    • 2016-09-04
    • 2015-04-01
    • 2012-02-15
    • 2023-03-18
    相关资源
    最近更新 更多