附录 B. 使用 Red Hat Maven 软件仓库


这部分论述了如何在软件中使用红帽提供的 Maven 存储库。

B.1. 使用在线软件仓库

红帽维护一个中央 Maven 存储库,用于基于 Maven 的项目。如需更多信息,请参阅 存储库欢迎页面

将 Maven 配置为使用红帽存储库的方法有两种:

将存储库添加到您的 Maven 设置中

此配置方法适用于用户拥有的所有 Maven 项目,只要您的 POM 文件不会覆盖存储库配置,并且启用了包含的配置集。

流程

  1. 找到 Maven settings.xml 文件。它通常位于用户主目录中的 .m2 目录中。如果文件不存在,则使用文本编辑器创建该文件。

    对于 Linux 或 UNIX:

    /home/<username>/.m2/settings.xml
    Copy to Clipboard Toggle word wrap

    在 Windows 上:

    C:\Users\<username>\.m2\settings.xml
    Copy to Clipboard Toggle word wrap
  2. 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>
    Copy to Clipboard Toggle word wrap

有关 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>
Copy to Clipboard Toggle word wrap

有关 POM 文件配置的更多信息,请参阅 Maven POM 参考

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat