领先一步
VMware 提供培训和认证,助您加速进步。
了解更多正如 Rob 的帖子所指出的,在过去的几个月里,我们对人们希望如何管理自己的 OSGi 应用程序有了一些了解。
我们发现,一些开发人员希望自己管理 bundle manifest,但需要一些帮助来自动化诸如为一系列导入指定包版本之类的事宜。其他开发人员则希望根据其项目的实际内容和构建文件中指定的依赖项来生成 manifest。此外,这两类开发人员都需要与现有库协同工作,这些库可能缺少启用它们在 OSGi 服务平台上使用的必要 OSGi 元数据。
Bundlor 为所有这些情况提供了一个解决方案,并且是我们一段时间以来用于管理发布到 SpringSource Enterprise Bundle Repository 的 bundles 的工具。Bundlor 可以在 JAR 创建后自动检测依赖项并为 JAR 创建 OSGi manifest 指令。它以 JAR 和一个由标准 OSGi manifest 头组成的超集作为输入。然后,它分析 JAR 中包含的源代码和支持文件,将模板应用于结果,并生成 manifest。
| Header | 描述 |
|---|---|
| Excluded-Exports | 必须不添加到 manifest 的逗号分隔的包列表Export-Packageheader。 |
| Excluded-Imports | 默认情况下,Bundlor 将为它确定被 jar 中的代码或特殊文件引用的每个包添加导入。此 header 允许指定一个逗号分隔的包列表,这些包将不会生成导入。 |
| Export-Template | 默认情况下,Bundlor 会为所有导出的包指定版本Bundle-Version。此 header 允许为单个导出的包指定不同的版本。例如:Export-Template com.foo.*;version="1.5"将导致任何Export-Package条目,用于com.foo或其子包,版本将为1.5. |
| Ignored-Existing-Headers | 对于正在生成 manifest 的 JAR 已经包含 OSGi 兼容 manifest 的情况,此 header 可用于列出 Bundlor 应忽略的原始 manifest 中的头。 |
| Import-Template | 此 header 用于增强 Bundlor 通过字节码和特殊文件分析生成的包导入。通常这是为了指定导入的版本,有时也用于将其标记为可选。header 的值是逗号分隔的包名称和属性列表。 |
以下是来自 Spring Binding bundle 的 Bundlor manifest 模板示例,展示了通配符和显式Import-Package语句的用法。
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.springframework.binding
Bundle-Name: Spring Binding
Bundle-Vendor: SpringSource
Import-Package:
ognl;version="[2.6.9, 3.0.0)";resolution:=optional,
org.jboss.el;version="[2.0.0, 3.0.0)";resolution:=optional
Import-Template:
org.springframework.*;version="[2.5.4.A, 3.0.0)",
org.apache.commons.logging;version="[1.1.1, 2.0.0)",
javax.el;version="[2.1.0, 3.0.0)";resolution:=optional
Bundlor 扫描以下类型
将 SpringSource Enterprise Bundle Repository 添加到pom.xml文件。
<pluginRepositories>
<pluginRepository>
<id>com.springsource.repository.bundles.milestone</id>
<name>SpringSource Enterprise Bundle Repository</name>
<url>http://repository.springsource.com/maven/bundles/milestone</url>
</pluginRepository>
...
</pluginRepositories>
将bundlor插件添加到pom.xml文件的标签
<build>
<plugins>
<plugin>
<groupId>com.springsource.bundlor</groupId>
<artifactId>com.springsource.bundlor.maven</artifactId>
<version>1.0.0.M2</version>
<executions>
<execution>
<id>bundlor</id>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
最后,使用 package 命令构建 bundle。
mvn install package
要从 ANT 内部运行 Bundlor,首先需要定义一个bundlornamespace。
<project name="bundlor-sample-ant"
xmlns:bundlor="antlib:com.springsource.bundlor.ant">
然后将 bundlor 任务导入到构建中。
<target name="bundlor.init">
<taskdef resource="com/springsource/bundlor/ant/antlib.xml"
uri="antlib:com.springsource.bundlor.ant">
<classpath id="bundlor.classpath">
<fileset dir="${bundlor.home}/dist"/>
<fileset dir="${bundlor.home}/lib"/>
</classpath>
</taskdef>
</target>
最后,使用bundlortask。
<bundlor:bundlor
bundlePath="${basedir}/org.springframework.integration.jar"
outputPath="${basedir}/target/org.springframework.integration.jar"
bundleVersion="1.0.2.BUILD-${timestamp}"
manifestTemplatePath="${basedir}/template.mf"/>
要从命令行运行 Bundlor,请切换到目录$BUNDLOR_HOME/bin目录并运行任一bundlor.sh或bundlor.bat.
% ./bundlor.sh transform \ --bundle ./org.springframework.integration.jar \ --manifest ./template.mf \ --outputfile ./target/org.springframework.integration.jar Transformed bundle written to ./target/org.springframework.integration.jar %