領先一步
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 %