附录 B. 使用 Red Hat Maven 软件仓库
这部分论述了如何在软件中使用红帽提供的 Maven 存储库。
B.1. 使用在线软件仓库 复制链接链接已复制到粘贴板!
红帽维护一个中央 Maven 存储库,用于基于 Maven 的项目。如需更多信息,请参阅 存储库欢迎页面。
将 Maven 配置为使用红帽存储库的方法有两种:
将存储库添加到您的 Maven 设置中
此配置方法适用于用户拥有的所有 Maven 项目,只要您的 POM 文件不会覆盖存储库配置,并且启用了包含的配置集。
流程
找到 Maven
settings.xml文件。它通常位于用户主目录中的.m2目录中。如果文件不存在,则使用文本编辑器创建该文件。对于 Linux 或 UNIX:
/home/<username>/.m2/settings.xml在 Windows 上:
C:\Users\<username>\.m2\settings.xml在
settings.xml文件的profile元素中添加包含红帽存储库的新配置集,如下例所示:示例:包含红帽存储库的 Maven
settings.xml文件<settings> <profiles> <profile> <id>red-hat</id> <repositories> <repository> <id>red-hat-ga</id> <url>https://maven.repository.redhat.com/ga</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>red-hat-ga</id> <url>https://maven.repository.redhat.com/ga</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>red-hat</activeProfile> </activeProfiles> </settings>
有关 Maven 配置的更多信息,请参阅 Maven 设置参考。
在 POM 文件中添加存储库
要直接在项目中配置存储库,请在 POM 文件的 repositories 元素中添加新条目,如下例所示:
示例:包含红帽存储库的 Maven pom.xml 文件
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example-app</artifactId>
<version>1.0.0</version>
<repositories>
<repository>
<id>red-hat-ga</id>
<url>https://maven.repository.redhat.com/ga</url>
</repository>
</repositories>
</project>
有关 POM 文件配置的更多信息,请参阅 Maven POM 参考。