領先一步
VMware 提供培訓和認證,以加速您的進度。
瞭解更多如同 Rob 的文章 指出,過去幾個月我們學到了很多人們想要如何管理自己的 OSGi 應用程式。
我們發現有些開發人員想要管理自己的 bundle 宣告檔案,但需要一些協助來自動化細節,例如指定一系列匯入的套件版本。 其他開發人員想要根據專案內容和建置檔案中指定的相依性來產生宣告檔案。 此外,這兩種開發人員都需要使用現有的函式庫,而這些函式庫沒有必要的 OSGi metadata,使其無法在 OSGi 服務平台上使用。
Bundlor 為所有這些情況提供了解決方案,而且是我們內部使用了一段時間的工具,用於管理發佈到 SpringSource Enterprise Bundle Repository 的 bundle。 Bundlor 會自動偵測相依性,並在建立 JAR 之後建立 JAR 的 OSGi 宣告指令。 它會將 JAR 和範本(包含標準 OSGi 宣告標頭的超集合)作為輸入。 然後,它會分析 JAR 中包含的原始程式碼和支援檔案,將範本套用到結果,並產生宣告。
標頭 | 說明 |
---|---|
Excluded-Exports | 以逗號分隔的套件清單,這些套件不得新增至宣告檔案的Export-Package標頭。 |
Excluded-Imports | 預設情況下,Bundlor 會為它判斷為程式碼或 jar 中的特殊檔案所參考的每個套件新增匯入。 此標頭允許指定以逗號分隔的套件清單,這些套件將不會產生匯入。 |
Export-Template | 預設情況下,Bundlor 會以指定的版本來版本化所有匯出的套件Bundle-Version。 此標頭允許以不同的版本匯出個別的匯出套件。 例如:Export-Template com.foo.*;version="1.5"會導致任何Export-Package的項目com.foo或其子套件的版本為1.5. |
Ignored-Existing-Headers | 對於產生宣告的 JAR 已經包含符合 OSGi 的宣告的情況,可以使用此標頭來列出 Bundlor 應該忽略的原始宣告中的標頭。 |
Import-Template | 此標頭用於擴充 Bundlor 透過位元組碼和特殊檔案分析產生的套件匯入。 通常,這是為了版本化匯入,並且在某些情況下,將它們標記為可選。 標頭的值是套件名稱和屬性的逗號分隔清單。 |
以下是 Spring Binding bundle 中的 Bundlor 宣告範本範例,顯示了萬用字元和明確的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,請先定義一個bundlor命名空間。
<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 %