利用 Maven 來自動執行 Liberty 設定檔作業
Apache Maven 是一個以專案物件模型 (POM) 概念為基礎的軟體專案管理工具。 您可以利用 Liberty 設定檔所提供的 Maven 外掛程式來管理伺服器和應用程式。
開始之前
Liberty 設定檔的 Maven 外掛程式是在 WebSphere® Application Server 開發人員社群 (WASdev) Maven 儲存庫中。如果您想要使用 Liberty 的 Maven 外掛程式,您必須確定在專案的 pom.xml 檔中指定了 WASdev 外掛程式儲存庫。
下列範例顯示如何配置這個儲存庫,以及在您的專案中啟用 liberty-maven-plugin。
<project>
...
<pluginRepositories>
<!-- 配置 WASdev 儲存庫 -->
<pluginRepository>
<id>WASdev</id>
<name>WASdev Repository</name>
<url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
...
<build>
<plugins>
<!-- 啟用 liberty-maven-plugin -->
<plugin>
<groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>1.0</version>
<!-- 指定配置,執行 liberty-maven-plugin -->
...
</plugin> </plugins>
</build>
...
</project>
Liberty Maven 外掛程式必須以 Liberty 設定檔伺服器安裝資訊來配置。
安裝資訊可以指定為現有的安裝目錄、壓縮保存檔或 Maven 構件。
- 配置現有的安裝目錄。
請利用 serverHome 參數來指定現有的 Liberty 設定檔伺服器安裝目錄。 例如:
... <plugin> <groupId>com.ibm.websphere.wlp.maven.plugins</groupId> <artifactId>liberty-maven-plugin</artifactId> <version>1.0</version> <configuration> <serverHome>/opt/ibm/wlp</serverHome> </configuration> </plugin> ...
- 配置壓縮保存檔。
請利用 assemblyArchive 參數來指定包含 Liberty 設定檔伺服器檔案的壓縮保存檔。 例如:
... <plugin> <groupId>com.ibm.websphere.wlp.maven.plugins</groupId> <artifactId>liberty-maven-plugin</artifactId> <version>1.0</version> <configuration> <assemblyArchive>/opt/ibm/wlp.zip</assemblyArchive> </configuration> </plugin> ...
- 配置 Maven 構件名稱。
請利用 assemblyArtifact 參數來指定包含 Liberty 設定檔伺服器檔案的 Maven 構件名稱。 例如:
如需將 Liberty 設定檔伺服器安裝為 Maven 構件的相關資訊,請參閱安裝為 Maven 構件。... <plugin> <groupId>com.ibm.websphere.wlp.maven.plugins</groupId> <artifactId>liberty-maven-plugin</artifactId> <version>1.0</version> <configuration> <assemblyArtifact> <groupId>com.ibm.ws.liberty.test</groupId> <artifactId>liberty-test-server</artifactId> <version>1.0</version> <type>zip</type> </assemblyArtifact> </configuration> </plugin> ...
關於這項作業
您可以利用所提供的 Maven 外掛程式來建立、啟動、停止和包裝 Liberty 設定檔伺服器,以及在 Liberty 設定檔測試您的應用程式。 每個作業都是由 Maven 中的特定目標來表示。