0

我正在开发 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 不存在。(我来宾此文件不在类路径中)

你知道如何让它工作吗?

4

1 回答 1

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

于 2012-03-29T19:22:25.663 回答