(4)项目构建之搭建maven私服

1.引言

      在一个公司当中往往会搭建自己的nexus私服,在本篇博客中主要介绍如何搭建自己的私服,如何将自己的jar发布到私服。

2.搭建nexus私服

2.1安装nexus私服

  • 下载nexus,在本篇博客中用到的是war版本,下载地址为:nexus
  • 将改war包复制到tomcat的webapp目录下(修改为nexus.war),如图所示:

这里写图片描述

这里写图片描述

2.2登录nexus私服

  • nexus私服的有着默认的用户名和密码(用户名:admin,密码:admin123)

这里写图片描述

2.3介绍nexus仓库

这里写图片描述

仓库的类型:
    proxy  :代理仓库,代理中央仓库的jar包
    hosted :宿主仓库,改仓库属于公司私有的
        3rd part:第三方的jar包,但是该jar包没有在中心仓库保存
        snapshot:本公司测试版本、镜像版本
        release:本公司的发行版本
    public :仓库组的概念,我们实际上是用仓库组
仓库的是路径:Repository Path属性
  • 仓库在服务器硬盘路径(点击仓库名称->仓库的配置->仓库地址):

远程仓库地址:

这里写图片描述

本地仓库地址:

这里写图片描述

  • 查看仓库组查找顺序

这里写图片描述

查找顺序:releases->snapshots->3rd party->central

2.4开发中使用私服

  • 在代码开发过程中,首先修改pom.xml文件,让本地仓库去私服查找
 <!-- 没有私服:
             本地仓库找不到,则访问中心仓库
      有私服: 
             首先访问本地仓库
             本地仓库没有,则访问私服仓库
             私服仓库也没有,则访问中心仓库
   -->
   <!-- 
       加载的是 第三方项目使用的jar包
       snapshots:设置为true是说,我可以下载测试版本(不建议)
       url:因为我的私服是在本机,所以是localhost
    -->
   <repositories>
    <repository>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>public</id>
      <name>public</name>
      <url>http://localhost:8080/nexus/content/groups/public/</url>
    </repository>
  </repositories>
   <!-- 加载的是maven生命周期插件的jar包 -->
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>public</id>
      <name>public</name>
      <url>http://localhost:8080/nexus/content/groups/public/</url>
    </pluginRepository>
  </pluginRepositories>
  • 如果我们开发的jar需要部署到私服,需要设置distributionManagement(POM.xml)
<distributionManagement>
  <!-- 发布到 快照版本的仓库,即 测试版本仓库 -->
  <snapshotRepository>
  <id>snapshots</id>
  <url>http://localhost:8080/nexus/content/repositories/snapshots/</url>
  </snapshotRepository>
  <!-- 发布到 发行版本的仓库中,也可以发布到3rd party 仓库 -->
  <repository>
    <id>releases</id>
    <url>http://localhost:8080/nexus/content/repositories/releases/</url>
  </repository>
</distributionManagement>
  • 如果发布到私服还需要设置server,私服的账户名密码(POM.XML)
    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  • 如果发布到私服,也可以设置setting 文件(也就是全局的)

这里写图片描述

2.5需要注意地方

  • xml的标签属性不要随便写(要和私服的id对应)例如:

这里写图片描述

3.总结

在本篇博客中主要介绍了:

  • 如果搭建自己的私服
  • 如果上传自己的jar到私服
  • 如果修改pom.xml从私服下载jar
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值