maven上传jar包到代码仓库

本文介绍了如何在Maven项目中配置Nexus仓库,包括在pom.xml中设置仓库地址,以及在settings.xml中配置账号密码。最后指导用户打包后通过mvndeploy命令将项目推送到仓库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、前言

    一般被引用的包开发都是要求放在nexus仓库中,等到有jar包服务需要引用该包的时候直接从nexus仓库中获取即可,实现了该引用包的公用

二、代码配置

    编辑代码中的pom.xml文件配置

    vi pom.xml

<distributionManagement>
    <repository>
        <id>nfd_nexus</id>   #自行命名id
        <name>nfd Repository</name>
        <url>http://10.1.60.112:8081/repository/nfd-releases/</url>  #使用nexus仓库的项目地址
    </repository>
    <snapshotRepository>
        <id>nfd_nexus</id>
        <name>nfd Snapshot Repository</name>
        <url>http://10.1.60.112:8081/repository/nfd-snapshots/</url> ##使用nexus仓库的项目地址
    </snapshotRepository>

</distributionManagement>

查看nexus仓库,复制项目存放目录的地址,粘贴到上面的配置中 

 这是配置好的pom.xml文件 

编辑maven的setting.xml配置文件,配置nexus仓库的账号密码

vi /etc/maven/apache-maven-3.9.0/conf/settings.xml

<servers>
  <server>
    <id>nfd_nexus</id>   #匹配上面的pom.xml的id
    <username>nfd</username>    #nexus仓库的用户名
    <password>11111111</password>  #nexus仓库的密码
  </server> 
</servers>
 <profiles>         #在profiles下配置nexus仓库地址
     <profile>
         <id>nfd_nexus</id>
            <repositories>
                    <repository>
                            <id>nfd_nexus</id>      
                            <url>http://10.1.60.112:8081/repository/nfd-public/</url>
                            <releases>
                                    <enabled>true</enabled>
                            </releases>
                            <snapshots>
                                    <enabled>true</enabled>
                            </snapshots>
                    </repository>
            </repositories>
     </profile>
  </profiles>
  <activeProfiles>     #启用配置
     <activeProfile>nfd_nexus</activeProfile>
  </activeProfiles>

 

使用http地址的nexus仓库需要注释禁止使用http项的配置

 vi /etc/maven/apache-maven-3.9.0/conf/settings.xml

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <!--   #该配置为禁止http请求,nexus需要使用http的话直接注释掉该配置
    <mirror>
      <id>maven-default-http-blocker</id>
      <mirrorOf>external:http:*</mirrorOf>
      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>
    -->
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>https://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

 

 

至此配置完成

代码打包完成后执行以下命令推送 到nexus仓库即可

mvn deploy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值