第五章、Maven私服

一、概述

私服的好处

  • 缓存Maven中央仓库的jar包,这样避免每次本地仓库没有jar包直接去中央仓库下载,而是先到私服下载。
  • 解决公司无法上网,而又要连接中央仓库的问题。只要连接私服,确保私服可以连接到中央仓库。
  • 方便公司内部不同团队或者项目共享jar包。需要共享jar包的,可以上传到私服,通过私服共享。

二、Nexus安装与仓库概念

Nexus下载地址:https://www.sonatype.com/nexus-repository-oss

1. 安装

  • 解压文件
  • 启动服务 nexus.exe /run (启动成功后不要关闭命令行窗口)
  • 安装服务 nexus.exe /install (重新使用新得命令行安装,可能出现权限不足,请以管理员身份运行命令行)
  • 启动服务 net start nexus
  • 停止服务 net stop nexus
  • 访问页面 http://localhost:8081
  • 初始登录用户名和密码:admin/admin123

注:启动nexus.exe不能使用传统得鼠标双击来运行启动,而是要通过如下的命令行键入命令启动

2. 查看修改Nexus端口

  • nexus-3.14.0/etc/nexus-default.properties ——application-port=8081 

3. 仓库 

  • 从Nexus私服下载资源(找到maven配置文件settings.xml,添加如下配置)
// 添加镜像配置,将所有访问外网仓库的请求指向私服
<mirror>
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://localhost:8081/repository/maven-public/</url>
</mirror>

// 添加profiles,所有请求均通过镜像
<profile>
    <id>nexus</id>
    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
    </pluginRepositories>
</profile>

// 生效配置
<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>
  • 上传资源到Nexus私服(添加路径同上)
<distributionManagement>
    <repository>
        <id>release></id>
        <name>Internal Release</name>
        <url>http://192.168.11.203:8081/nexus/content/repositories/release</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <url>http://192.168.11.203:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>

在maven的配置文件中配置上传权限

<server>
    <id>release</id>
    <username>admin</username>
    <password>admin123</password>
</server>
<server>
    <id>snapshots</id>
    <username>deployment</username>
    <password>deployment123</password>
</server>

通过mvn deploy命令将工程打包成jar发布到nexus私服中

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值