避免在两个不同的罐子中冲突相同的包装

时间:2013-12-03 11:24:05

标签: java osgi osgi-bundle

我为五个罐子开发了一个OSGI包

poi-3.9 - bundle name:- org.apache.poi
poi-ooxml-3.9- bundle name:- org.apache.poi.ooxml
poi-ooxml-schemas
dom4j
xmlbeans

但是当我使用这些罐子时会出现错误

NoClassDef found 
org.apache.poi.ss.usermodel.WorkbookFactory

然后我意识到了一些包(比如org.apache.poi.ss.usermodel)

poi-3.9
poi-ooxml-3.9 jars are same 
then i use 
Require-Bundle: 
 org.apache.poi;visibility:=reexport,
 org.apache.poi.ooxml;visibility:=reexport

它会产生同样的错误 我该怎么做才能解决这个问题

清单文件

Bundle-ManifestVersion: 1
Bundle-Name: poi
Bundle-SymbolicName: org.apache.poi
Bundle-Version: 3.9
Bundle-Vendor: XYZ
Bundle-Localization: plugin
Import-Package: org.apache.poi.ss.usermodel
Export-Package: org.apache.poi,
org.apache.poi.common.usermodel,
org.apache.poi.ddf,
org.apache.poi.dev,
org.apache.poi.hpsf,
org.apache.poi.hpsf.extractor,
org.apache.poi.hpsf.wellknown,
org.apache.poi.hssf,
org.apache.poi.hssf.dev,
org.apache.poi.hssf.eventmodel,
org.apache.poi.hssf.eventusermodel,
org.apache.poi.hssf.eventusermodel.dummyrecord,
org.apache.poi.hssf.extractor,
org.apache.poi.hssf.model,
 org.apache.poi.hssf.record,
 org.apache.poi.hssf.record.aggregates,
 org.apache.poi.hssf.record.cf,
 org.apache.poi.hssf.record.chart,
 org.apache.poi.hssf.record.common,
 org.apache.poi.hssf.record.cont,
 org.apache.poi.hssf.record.crypto,
 org.apache.poi.hssf.record.pivottable,
 org.apache.poi.hssf.usermodel,
 org.apache.poi.hssf.util,
 org.apache.poi.poifs.common,
 org.apache.poi.poifs.crypt,
 org.apache.poi.poifs.dev,
 org.apache.poi.poifs.eventfilesystem,
 org.apache.poi.poifs.filesystem,
 org.apache.poi.poifs.nio,
 org.apache.poi.poifs.property,
 org.apache.poi.poifs.storage,
 org.apache.poi.ss,
 org.apache.poi.ss.extractor,
 org.apache.poi.ss.format,
 org.apache.poi.ss.formula,
 org.apache.poi.ss.formula.atp,
 org.apache.poi.ss.formula.constant,
 org.apache.poi.ss.formula.eval,
 org.apache.poi.ss.formula.eval.forked,
 org.apache.poi.ss.formula.function,
 org.apache.poi.ss.formula.functions,
 org.apache.poi.ss.formula.ptg,
 org.apache.poi.ss.formula.udf,
 org.apache.poi.ss.usermodel,
 org.apache.poi.ss.usermodel.charts,
 org.apache.poi.ss.util,
 org.apache.poi.ss.util.cellwalk,`enter code here`
 org.apache.poi.util

第二个清单

Bundle-ManifestVersion: 1
Bundle-Name: poi.ooxml
Bundle-SymbolicName: org.apache.poi.ooxml
Bundle-Version: 3.9
Bundle-Vendor: xyz
Bundle-Localization: plugin
Require-Bundle: org.apache.poi.ooxml.schemas,
 org.apache.poi.dom4j,
 org.apache.poi.xmlbeans
Import-Package: org.apache.poi.ss.usermodel
Export-Package: org.apache.poi,
 org.apache.poi.dev,
 org.apache.poi.extractor,
 org.apache.poi.openxml4j.exceptions,
 org.apache.poi.openxml4j.opc,
 org.apache.poi.openxml4j.opc.internal,
 org.apache.poi.openxml4j.opc.internal.marshallers,
 org.apache.poi.openxml4j.opc.internal.signature,
 org.apache.poi.openxml4j.opc.internal.unmarshallers,
 org.apache.poi.openxml4j.opc.signature,
 org.apache.poi.openxml4j.util,
 org.apache.poi.ss.usermodel,
 org.apache.poi.util,
 org.apache.poi.xslf,
 org.apache.poi.xslf.extractor,
 org.apache.poi.xslf.model,
 org.apache.poi.xslf.model.geom,
 org.apache.poi.xslf.usermodel,
 org.apache.poi.xslf.util,
 org.apache.poi.xssf.dev,
 org.apache.poi.xssf.eventusermodel,
 org.apache.poi.xssf.extractor,
 org.apache.poi.xssf.model,
 org.apache.poi.xssf.streaming,
 org.apache.poi.xssf.usermodel,
 org.apache.poi.xssf.usermodel.charts,
 org.apache.poi.xssf.usermodel.extensions,
 org.apache.poi.xssf.usermodel.helpers,
 org.apache.poi.xssf.util,
 org.apache.poi.xwpf.extractor,
 org.apache.poi.xwpf.model,
 org.apache.poi.xwpf.usermodel

1 个答案:

答案 0 :(得分:0)

首先:你真的需要将poi罐子转换成束吗?如果您只使用另一个包中的代码,那么将jar包含到该包中并相应地调整bundle类路径可能是明智的。这可能会为您节省很多问题,特别是如果您不熟悉将现有jar转换为OSGi包。

我快速浏览了poi发行版,并且包的名称可能相同,但内容不一样(拆分包)。这意味着这里最简单的选择是创建一个新的包jar,包括来自poi的所有类和来自发行版的poi-ooxml jar。然后使用Export-Package标题从该包中导出所有包。