maven配置远程仓库私服的服务器账号、密码

10 篇文章 0 订阅
9 篇文章 0 订阅

首先需要配置远程仓库私服的服务器账号、密码,找到maven的settings.xml文件,配置<server>,里边的ID注意,就是标识你仓库的唯一ID,可以根据你的仓库随意起名就行。

  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
    <!-- 在这里添加配置私仓的ID和账号、密码 -->
	<server>
      <id>mycentral</id>
      <username>私服账号</username>
      <password>私服密码</password>
    </server>
	<server>
      <id>mysnapshots</id>
      <username>私服账号</username>
      <password>私服密码</password>
    </server>
  </servers>

然后找到你代码工程中的pom.xml文件,配置<distributionManagement>或<repositories>,这2个字段的区别就是

distributionManagement是使用mavne deploy上传打好的包。

repositories就跟打包上传无关,只是你想在POM中配置其它的远程仓库。

所以你可以根据需要全部配置或只配置其中一个。注意其中的ID,一定要和你在settings.xml中配置server账号的ID保持一致,才能关联生效

<distributionManagement>
        <repository>
            <!--注意ID配置与settings.xml中server配置ID保持一致-->
            <id>mycentral</id>
            <name>Artifactory-releases</name>
            <url>https://私仓地址.com.cn/artifactory/Management_Application_Maven</url>
        </repository>
        <snapshotRepository>
            <id>mysnapshots</id>
            <name>Artifactory-snapshots</name>
            <url>https://私仓地址.com.cn/artifactory/Management_Application_Maven</url>
        </snapshotRepository>
</distributionManagement>
    <repositories>
        <repository>
            <!--注意ID配置与settings.xml中server配置ID保持一致-->
            <id>mysnapshots</id>
            <url>https://devstack.vgc.com.cn/artifactory/Timesheet_Management_Application_Maven</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <!--注意ID配置与settings.xml中server配置ID保持一致-->
            <id>mycentral</id>
            <url>https://devstack.vgc.com.cn/artifactory/Timesheet_Management_Application_Maven</url>
        </repository>
        <repository>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

Maven是一个开源的项目管理工具,使用它可以更方便地构建、管理和发布项目。配置远程仓库是使用Maven的一个重要环节,它可以帮助我们引入和下载所需的依赖库。 以下是配置远程仓库的步骤: 1. 打开Maven项目的pom.xml文件,该文件是Maven项目的核心配置文件。 2. 在pom.xml文件中,找到<repositories>节点,该节点用于配置远程仓库信息。 3. 在<repositories>节点下,添加<repository>子节点,并在其中配置仓库信息。 4. 配置<repository>子节点的属性,其中包括<id>、<url>和<releases>等。 - <id>用于唯一标识仓库,一般可以使用仓库的名称或者URL。 - <url>是远程仓库的URL地址,可以是公共仓库、私有仓库或者本地仓库的URL。 - <releases>用于配置仓库的发布策略,可以设置为true或者false。如果设置为true,则表示从该仓库下载项目的正式版本。 5. 配置完<repository>子节点后,保存pom.xml文件。 6. 在使用Maven构建项目时,Maven将会根据配置远程仓库信息,从远程仓库中下载所需的依赖库。 需要注意的是,远程仓库一般需要有相应的权限,才能从中下载依赖库。因此,在配置远程仓库之前,需要确保已经获得了访问该仓库的权限。 以上就是使用Maven配置远程仓库的简单步骤。配置远程仓库后,我们就可以方便地引入所需的第三方库,并构建我们的项目了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值