简体   繁体   English

OSGI Import-Package:版本vs bundle-version - 有什么区别?

[英]OSGI Import-Package: version vs bundle-version - what's the difference?

I'm having trouble getting an OSGi bundle loaded into a third party framework. 我无法将OSGi包加载到第三方框架中。 It keeps rejecting my bundle because I am specifying Import-Package versions that do not exist, even though I know they are loading the bundles with the versions I want/need. 它一直拒绝我的捆绑包,因为我指定了不存在的Import-Package版本,即使我知道他们正在使用我想要/需要的版本加载捆绑包。 To get around the problem, I have temporarily disabled my version requirements, but it is a little ugly. 为了解决这个问题,我暂时禁用了我的版本要求,但它有点难看。

Import-Package: com.ghc.ghTester.expressions,org.apache.ws.security;vers
 ion=0,org.apache.ws.security.components.crypto;version=0,org.apache.ws.
 security.message;version=0,org.apache.ws.security.message.token;version
 =0,org.apache.ws.security.processor;version=0

When I look at the Manifest for my dependency, I see: 当我查看Manifest的依赖时,我看到:

Bundle-Version: 1.5.11
Bundle-ClassPath: wss4j-1.5.11.jar
Bundle-Vendor: Apache
Export-Package: org.apache.ws.axis.security,
 org.apache.ws.axis.security.handler,
 org.apache.ws.security,
 org.apache.ws.security.action,
 org.apache.ws.security.components.crypto,
 org.apache.ws.security.conversation,
 org.apache.ws.security.conversation.dkalgo,
 org.apache.ws.security.handler,
 org.apache.ws.security.message,
 org.apache.ws.security.message.token,
 org.apache.ws.security.processor,
 org.apache.ws.security.saml,
 org.apache.ws.security.transform,
 org.apache.ws.security.util

After complaining to the Framework team, they have told me that I need to use bundle-version and not version in my Import-Package statement, such as: 在向Framework团队抱怨之后,他们告诉我我需要在我的Import-Package语句中使用bundle-version而不是version ,例如:

Import-Pacakge: org.apache.ws.security;bundle-version=[1.5.0,2)

I've read through the OSGi Specs (page 50) , but cannot seem to understand the nuance between these two values: 我已经阅读了OSGi规范(第50页) ,但似乎无法理解这两个值之间的细微差别:

The developer can specify arbitrary matching attributes. 开发人员可以指定任意匹配属性。 See Attribute Matching on page 58. The following arbitrary matching attributes are predefined: 请参见属性匹配(第58页)。预定义了以下任意匹配属性:

• version - A version-range to select the exporter's package version. •version - 用于选择导出程序包版本的版本范围。 The syntax must follow Version Ranges on page 36. For more information on version selection, see Semantic Versioning on page 54. If this attribute is not specified, it is assumed to be [0.0.0, ∞). 语法必须遵循版本范围(第36页)。有关版本选择的详细信息,请参阅第54页的语义版本控制。如果未指定此属性,则假定为[0.0.0,∞)。

• specification-version - This attribute is an alias of the version attribute only to ease migration from earlier versions. •specification-version - 此属性是version属性的别名,仅用于简化从早期版本的迁移。 If the version attribute is present, the values must be equal. 如果存在version属性,则值必须相等。

• bundle-symbolic-name - The bundle symbolic name of the exporting bundle. •bundle-symbolic-name - 导出包的包符号名称。 In the case of a fragment bundle, this will be the host bundle's symbolic name. 对于片段包,这将是主机包的符号名称。

• bundle-version - A version-range to select the bundle version of the exporting bundle. •bundle-version - 用于选择导出捆绑包的捆绑版本的版本范围。 The default value is [0.0.0, ∞). 默认值为[0.0.0,∞)。 See Semantic Versioning on page 54. In the case of a fragment bundle, the version is from the host bundle. 请参见第54页的语义版本控制。对于片段包,版本来自主机包。

Can someone please clarify the difference between the version and the bundle-version ? 有人可以澄清versionbundle-version之间的区别吗? From the way I read the docs, the bundle-version (ie: the manifest's Bundle-Version ) would extend to all packages in the bundle. 从我阅读文档的方式来看,bundle-version(即:manifest的Bundle-Version )将扩展到bundle中的所有包。 So wouldn't the package version (ie: version) be the same as the bundle-version (ie: bundle-version) on the Import-Package statement? 那么包版本(即:version)是否与Import-Package语句中的bundle-version(即:bundle-version)相同? Why is there an ability to specify the two differently? 为什么有能力以不同的方式指定两者?

It's pretty simple: bundle-version binds you to the version of the bundle that is exporting the package, whereas version binds to the version of the package itself. 它非常简单: bundle-version将您绑定到导出包的bundle的版本,而version绑定到包本身的版本。

You almost never want to use bundle-version on imports. 你几乎从来没有想用bundle-version进口。 The version of the exporting bundle is pretty much irrelevant... in fact when you are importing a package you shouldn't even care about the identity of the bundle exporting it. 导出包的版本几乎无关紧要......事实上,当您导入包时,您甚至不应该关心导出它的包的标识。 It's the package you care about, not the bundle it comes from. 这是你关心的包,而不是它来自的包。

Who told you to use bundle-version ? 谁告诉你使用bundle-version There might be some very special reason for this, but I doubt it. 可能有一些非常特殊的原因,但我对此表示怀疑。 More likely the person who told you this is just mistaken. 更有可能是告诉你这个的人错了。

You asked: 您询问:

So wouldn't the package version (ie: version) be the same as the bundle-version (ie: bundle-version) on the Import-Package statement? 那么包版本(即:version)是否与Import-Package语句中的bundle-version(即:bundle-version)相同?

No it isn't! 不,不是! Bundle version has nothing to do with package version. 捆绑版本与包版本无关。 When you change a package, you change the version of that package. 更改包时,您可以更改该包的版本。 The bundle is just a delivery mechanism. 捆绑只是一种交付机制。

UPDATE UPDATE

Rereading your question, I notice that the version of the packages exported by the dependency is not specified. 重读您的问题,我注意到未指定依赖项导出的包的版本。 That means that the framework is exporting everything as version 0.0.0, since that is the "default" version when a version is not specified. 这意味着框架将所有内容导出为版本0.0.0,因为这是未指定版本时的“默认”版本。 The version of a package emphatically does NOT default to the version of the bundle it lives in. Unfortunately it seems that the author of this framework does not have a good understanding of OSGi. 一个软件包的版本着重并不默认它所在的软件包的版本。不幸的是,这个框架的作者似乎对OSGi没有很好的理解。

UPDATE 2 更新2

Since the framework you are using does not provide versions, I recommend creating a no-code wrapper bundle that re-exports the packages with a proper version attached. 由于您使用的框架不提供版本,因此我建议创建一个无代码包装程序包,它可以使用附加的适当版本重新导出包。 This is quite simple to build, and it will keep all the ugliness in one place. 这个构建起来非常简单,它将把所有的丑陋都保存在一个地方。 Then any of your other bundles can simply import the packages with normal versions. 然后,您的任何其他捆绑包都可以使用普通版本导入包。

Since you haven't told me the BSN of the problematic bundle I will call it "org.foo". 既然你没有告诉我有问题的捆绑的BSN,我会称之为“org.foo”。 First create a file called manifest.txt as follows: 首先创建一个名为manifest.txt的文件,如下所示:

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.wrapper
Bundle-Version: 1.5.11
Require-Bundle: org.foo; bundle-version="[1.5.11,1.5.11]"
Export-Package: org.apache.ws.axis.security;version=1.5,
 org.apache.ws.axis.security.handler;version=1.5,
 ...

(Obviously I have made some other assumptions about versions here which you can correct.) (显然我已经对这里的版本做了一些其他假设,你可以纠正。)

Now build the bundle with: 现在构建包:

jar cfm wrapper.jar manifest.txt

Now that you have this bundle, your normal bundle can import a package like this: 现在你有了这个包,你的普通包可以导入这样的包:

Import-Package: org.apache.ws.security; version="[1.5,2)"

Hopefully you are using a tool based on bnd, in which case the Import-Package header will be generated for you including the version range. 希望您使用的是基于bnd的工具,在这种情况下,将为您生成包含版本范围的Import-Package标头。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSGi:Import-Package / Export-Package和Require-Capability / Provide Capability之间有什么区别? - OSGi: What's the difference between Import-Package/Export-Package and Require-Capability/Provide Capability? OSGI捆绑包.bnd文件和冲突的导入包语句 - OSGI bundle .bnd file and conflicting import-package statements 从OSGI命令提示符运行OSGI捆绑包:导入包缺少约束 - Running OSGI bundle from OSGI command prompt :Import-package missing constraint 为什么此OSGi导入包不起作用? - Why does this OSGi Import-Package not work? 捆绑XYZ无法解决。 原因:缺少约束:导入包:ABC; 无头RCP独立版本中的版本=“1.0.0”错误 - The bundle XYZ could not resolved. Reason: Missing Constraint: Import-Package: ABC; version=“1.0.0” error in headless RCP standalone 读取OSGI捆绑版本 - Read OSGI bundle version 软件包使用冲突:Import-Package:de.foo.bar; 版本=“0.0.0” - Package uses conflict: Import-Package: de.foo.bar; version=“0.0.0” 尽管有Import-Package,但org.osgi.framework.BundleActivator的ClassNotFoundException - ClassNotFoundException for org.osgi.framework.BundleActivator despite of Import-Package 未解决的要求:导入包:com.liferay.docs.guestbook.model; 版本="[1.0.0,1.1.0)"_ - Unresolved requirement: Import-Package: com.liferay.docs.guestbook.model; version="[1.0.0,1.1.0)"_ 如何在OSGi中添加特定包版本的import-packages - How to add import-packages from a specific bundle version in OSGi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM