利用 Maven 來自動執行 Liberty 作業
Apache Maven 是一個以專案物件模型 (POM) 概念為基礎的軟體專案管理工具。您可以利用 Liberty 所提供的 Maven 外掛程式,來管理伺服器和應用程式。
開始之前
Liberty 的 Maven 外掛程式是在 WebSphere® Application Server 開發人員社群 (WASdev) Maven 儲存庫中。如果您想要使用 Liberty 的 Maven 外掛程式,您必須確定在專案的 pom.xml 檔中指定了 WASdev 外掛程式儲存庫。
下列範例顯示如何配置這個儲存庫,以及在您的專案中啟用 liberty-maven-plugin。
<project>
...
<pluginRepositories>
<!-- Configure WASdev repository -->
<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>
<!-- Enable liberty-maven-plugin -->
<plugin>
<groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>1.0</version>
<!-- Specify configuration, executions for 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 中的特定目標來表示。