版本 3.1 - 最后修订于 2005 年 6 月 20 日
捆绑软件可以将有关它自己的描述性信息存储在名为 META-INF/MANIFEST.MF 的清单文件中。OSGi R4 框架规范定义了一组清单头,如 Export-Package 和 Bundle-Classpath,捆绑软件开发者使用这些清单头来提供关于捆绑软件的描述性信息。Eclipse OSGi 框架实现了完整 OSGi R4 框架规范和所有“核心框架”服务。OSGi R4 核心框架服务包括下列内容:
OSGi R4 规范定义了许多可选服务。可选服务未与 Eclipse OSGi 框架实现包括在一起。要了解有关 OSGi R4 清单头和服务的信息,请参阅 OSGi 规范。
Eclipse OSGi 框架支持许多附加的捆绑软件清单头和伪指令。捆绑软件开发者可以通过这些附加的头和伪指令来利用一些 Eclipse OSGi 框架中未被指定为标准 OSGi R4 框架一部分的的附加功能。
Eclipse OSGi 框架在 Export-Package 头中支持附加的伪指令。这些伪指令用来指定已导出包的访问限制规则。请参阅 osgi.resolverMode 以将 Eclipse OSGi 框架配置为在运行时强制执行访问限制规则。
可以在 Export-Package 头中使用 x-internal 伪指令来指定该包是否是内部包。插件开发环境不鼓励其他捆绑软件使用内部包。如果未指定 x-internal 伪指令,则将使用缺省值“false”。x-internal 伪指令必须使用以下语法:
x-internal ::= ( 'true' | 'false' )
下面是 x-internal 伪指令的示例:
Export-Package: org.eclipse.foo.internal; x-internal:=true
可以在 Export-Package 头中使用 x-friends 伪指令来指定一系列被允许访问该包的捆绑软件。插件开发环境不鼓励其他捆绑软件使用该包。x-friends 伪指令必须使用以下语法:
x-friends ::= '"' ( target-bundle ) ( ',' target-bundle ) * '"' target-bundle ::= a bundle symbolic name
下面是 x-friends 伪指令的示例:
Export-Package: org.eclipse.foo.formyfriends; x-friends:="org.eclipse.foo.friend1, org.eclipse.foo.friend2"
此示例指定应该只鼓励捆绑软件 org.eclipse.foo.friend1 和 org.eclipse.foo.friend2 使用 org.eclipse.foo.formyfriends 包。x-internal 包优先于 x-friends 伪指令。如果 x-internal 伪指令指定了“true”,则插件开发环境不鼓励所有捆绑软件使用该包,即使它们被指定为友元亦如此。
Eclipse-LazyStart 头用来指定是否应该在访问捆绑软件中的第一个类或资源之前自动启动该捆绑软件。此功能允许 Eclipse 在第一次需要使用捆绑软件时以惰性方式激活它们。通过使用此模型,Eclipse 就可以尽可能地减少启动时处于活动状态的捆绑软件。Eclipse-LazyStart 头必须使用以下语法:
Eclipse-LazyStart ::= ( 'true' | 'false' ) ( ';' 'exceptions' '=' '"' exceptions-list '"' ) ? exceptions-list ::= a comma ',' separated list of packages
使用“exceptions”属性来指定一系列包,当从这些包中装入类或资源时,一定不能导致激活捆绑软件。如果在捆绑软件清单中未定义 Eclipse-LazyStart 头,则将使用缺省值“false”。下面是 Eclipse-LazyStart 头的示例:
Eclipse-LazyStart: true; exceptions="org.eclipse.foo1, org.eclipse.foo2"
此示例指定除了“org.eclipse.foo1”和“org.eclipse.foo2”包中的类和资源以外,对于从此捆绑软件中装入的任何类或资源,都必须激活此捆绑软件。
在 Eclipse 中,不推荐使用 Eclipse-AutoStart 头。应该改为使用 Eclipse-LazyStart 头。
使用 Eclipse-PlatformFilter 来为捆绑软件指定平台过滤器。该平台过滤器在正在运行的平台中必须求值为 true 才允许解析该捆绑软件。Eclipse-PlatformFilter 头必须使用以下语法:
Eclipse-PlatformFilter ::= a valid LDAP filter string
框架支持对下列系统属性进行过滤:
下面是 Eclipse-PlatformFilter 头的示例:
Eclipse-PlatformFilter: (& (osgi.ws=win32) (osgi.os=win32) (osgi.arch=x86))
此示例指定仅当平台属性是 osgi.ws=win32、osgi.os=win32 和 osgi.arch=x86 时才可以对此捆绑软件进行解析(换而言之,在 x86 体系结构上使用 win32 操作系统和 win32 窗口系统运行的平台)。
使用 Eclipse-BuddyPolicy 头来为捆绑软件指定伙伴类装入策略。Eclipse-BuddyPolicy 头必须使用以下语法:
Eclipse-BuddyPolicy ::= ( policy-name ) ( ',' policy-name ) * policy-name ::= ( 'dependent' | 'global' | 'registered' | 'app' | 'ext' | 'boot' | 'parent' )
下面是 Eclipse-BuddyPolicy 头的示例:
Eclipse-BuddyPolicy: dependent
使用 Eclipse-RegisterBuddy 头来指定一系列捆绑软件,此捆绑软件将被注册为那些捆绑软件的伙伴。Eclipse-RegisterBuddy 头必须使用以下语法:
Eclipse-RegisterBuddy ::= ( target-bundle ) ( ',' target-bundle ) * target-bundle ::= a bundle symbolic name
下面是 Eclipse-RegisterBuddy 头的示例:
Eclipse-RegisterBuddy: org.eclipse.foo.bundle1, org.eclipse.foo.bundle2
Eclipse-ExtensibleAPI 用来指定主捆绑软件是否允许段捆绑软件对该主捆绑软件添加其他 API。如果主捆绑软件希望允许段捆绑软件将其他包添加到该主捆绑软件的 API 中,则应该使用此头。如果未指定此头,则将使用缺省值“false”。Eclipse-ExtensibleAPI 头必须使用以下语法:
Eclipse-ExtensibleAPI ::= ( 'true' | 'false' )
下面是 Eclipse-ExtensibleAPI 头的示例:
Eclipse-ExtensibleAPI: true
Eclipse-GenericCapability 头用来指定捆绑软件的通用功能。通用功能可以用来描述捆绑软件的功能部件,系统中的其他捆绑软件可能需要这些功能部件(通过 Eclipse-GenericRequire 头来使用这些功能部件)。通用功能具有名称和功能类型。功能类型由提供该功能的捆绑软件定义。功能还可以具有一组类型化的匹配属性,在解析 Eclipse-GenericRequire 头时,将使用这些属性来进行匹配。匹配属性可以是下列其中一种类型:[string | version | uri | long | double | set]。set 类型可用来将一组字符串定义成用逗号分隔的字符串列表。Eclipse-GenericCapability 头必须使用以下语法:
Eclipse-GenericCapability ::= capability ( ',' capability ) * capability ::= typed-name ( ';' typed-name ) * ( ';' typed-param ) * typed-name ::= name ( ':' capability-type ) typed-param ::= typed-key '=' quouted-string typed-key ::= name ( ':' [string | version | uri | long | double | set] )
以下是 Eclipse-GenericCapabilty 头的一个示例,它可用来指定提供了 OSGi 服务 org.acme.stuff.SomeService 实现的捆绑软件:
Eclipse-GenericCapability: org.acme.stuff.SomeService:osgi.service; version:version="1.0.1"
Eclipse-GenericRequire 头用来指定需要使用另一捆绑软件使用 Eclipse-GenericCapability 头提供的通用功能。通用需求具有名称和功能类型。功能类型由提供该功能的捆绑软件定义。通用需求可以指定 LDAP 过滤器字符串,此字符串是用于解析匹配的通用功能的选择过滤器。Eclipse-GenericRequire 头必须使用以下语法:
Eclipse-GenericRequire ::= generic-require ( ',' generic-require ) * generic-require ::= typed-name ( ';' typed-name ) * ( ';' selection-filter '=' quoated-ldapFilter ) ( ';' optional '=' [true|false] ) ( ';' multiple '=' [true|false] ) typed-name ::= name ( ':' capability-type )
以下是 Eclipse-GenericRequire 头的一个示例,它可用来指定依赖于 OSGi 服务 org.acme.stuff.SomeService 实现的捆绑软件:
Eclipse-GenericRequire: org.acme.stuff.SomeService:osgi.service; selection-filter="(version>=1.0.1)"
osgi.genericAliases 选项可用来将现有的 OSGi 清单头映射到 Eclipse-GenericCapability 和 Eclipse-GenericRequire 清单头。例如,请考虑以下清单头:
Export-Service: org.acme.stuff.SomeService Import-Service: org.acme.stuff.SomeService
通过使用以下属性,可以将这些头映射到 Eclipse-GenericCapability 和 Eclipse-GenericRequire 头:
osgi.genericAliases=Export-Service:Import-Service:osgi.service
实际上,这将转换为以下通用头:
Eclipse-GenericRequire: org.acme.stuff.SomeService:osgi.service Eclipse-GenericCapability: org.acme.stuff.SomeService:osgi.service
Plugin-Class 头仅用来支持为 Eclipse 2.1 平台开发的插件。此头用来指定一个类名,该类使用旧的 Eclipse 2.1 激活模型来激活插件。为 Eclipse 3.0 或更高版本开发的新捆绑软件不应该使用此头。下面是 Plugin-Class 头的示例:
Plugin-Class: org.eclipse.foo.FooPlugin