保持領先
VMware 提供培訓和認證,助您加速進步。
瞭解更多正如 Rob 的文章 所指出的,過去幾個月裡,我們對人們如何管理自己的 OSGi 應用程式有了不少了解。
我們發現,一些開發者希望自己管理 bundle manifests,但需要一些幫助來自動化細節,例如跨各種匯入指定包版本。另一些開發者則希望根據專案內容和構建檔案中指定的依賴關係生成 manifests。此外,這兩類開發者都需要使用沒有必要 OSGi 元資料(使其能夠在 OSGi 服務平臺中使用)的現有庫。
Bundlor 為所有這些情況提供瞭解決方案,並且是我們內部長期以來用於管理釋出到 SpringSource Enterprise Bundle Repository 的 bundles 的工具。Bundlor 自動化檢測依賴關係並在 JAR 建立後生成 OSGi manifest 指令。它接收一個 JAR 和一個包含標準 OSGi manifest header 超集的模板作為輸入。然後它分析 JAR 中包含的原始碼和支援檔案,將模板應用於結果,並生成一個 manifest。
Header | 描述 |
---|---|
Excluded-Exports | 一個逗號分隔的包列表,不得新增到 manifest 的Export-Packageheader 中。 |
Excluded-Imports | 預設情況下,Bundlor 會為它確定由 jar 中的程式碼或特殊檔案引用的每個包新增匯入。此 header 允許指定一個逗號分隔的包列表,Bundlor 不會為其生成匯入。 |
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 可用於列出原始 manifest 中 Bundlor 應忽略的 header。 |
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>
最後,使用bundlor任務。
<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 %