使用 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 工件来安装的更多信息,请参阅 Liberty:作为 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 中的特定目标来表示。