Maven总结3/3-----私服、第三方jar包的上传和下载

相关文章
Maven总结1/3-----概述
Maven总结2/3-----maven工程拆分与聚合

nexus私服的安装和启动

(1)安装和启动

下载nexus的jar包,并下载安装
在这里插入图片描述

在这里插入图片描述

从 浏览器输入: http://localhost:8081/nexus

在这里插入图片描述

(2)登录

在这里插入图片描述

(3)仓库类型

仓库种类
在这里插入图片描述

(4)常用组的配置:

在这里插入图片描述

nexus上传和下载jar包

(1)上传jar包

第一步:配置setting.xml文件

需要在客户端即部署工程的电脑上配置maven 环境,并修改settings.xml文件,配置连接私服的用户和密码 。 此用户名和密码用于私服校验,因为私服需要知道上传的账号和密码是否和私服中的账号和密码一致。
maven包的setting文件如下:

<server>
    <id>releases</id>
    <username>admin</username>
    <password>admin123</password>
</server>
<server>
    <id>snapshots</id>
    <username>admin</username>
    <password>admin123</password>
</server>

releases 连接发布版本项目仓库;snapshots 连接测试版本项目仓库

第二步: 配置项目 pom.xml

配置私服仓库的地址,本公司的自己的 jar 包会上传到私服的宿主仓库,根据工程的版本号 决定上传到哪个宿主仓库,如果版本为 release 则上传到私服的 release 仓库,如果版本为 snapshot 则上传到私服的 snapshot 仓库。
将下面的代码复制到要上穿jar包的pom文件中:

<distributionManagement>
    <repository>
        <id>releases</id>
        <url>http://localhost:8081/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

在这里插入图片描述
注意:pom.xml 这里 和 settings.xml 配置 对应!

测试:查看上传完成的jar包
在这里插入图片描述

(2)下载jar包

在本地安装的mavne包中Setting.xml文件中,写入如下配置:

<profile>
    <!--profile 的 id-->
    <id>dev</id>
    <repositories>
        <repository>
            <!--仓库 id,repositories 可以配置多个仓库,保证 id 不重复-->
            <id>nexus</id>
            <!--仓库地址,即 nexus 仓库组的地址-->
            <url>http://localhost:8081/nexus/content/groups/public/</url>
            <!--是否下载 releases 构件-->
            <releases>
                <enabled>true</enabled>
            </releases>
            <!--是否下载 snapshots 构件-->
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <!--  插件仓库,maven 的运行依赖插件,也需要从私服下载插件 -->
        <pluginRepository>
            <!--  插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边 -->
            <id>public</id>
            <name>Public Repositories</name>
            <url>http://localhost:8081/nexus/content/groups/public/</url>
        </pluginRepository>
    </pluginRepositories>
</profile>

使用 profile 定义仓库需要激活才可生效。

<activeProfiles>
    <activeProfile>dev</activeProfile>
</activeProfiles>

测试:点击运行,即可在控制台看到下载的jar包
在这里插入图片描述
在这里插入图片描述

安装和下载第三方jar包

(1)安装第三方jar包到本地仓库

进入jar包所在目录运行

mvn install:install-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dfile=fastjson-1.1.37.jar -Dpackaging=jar

打开cmd直接运行

mvn install:install-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=D:\material\Thirdjar\fastjson-1.1.37.jar

(2)安装第三方jar包到私服

在settings配置文件中添加登录私服第三方登录信息

<server>
    <id>thirdparty</id>
    <username>admin</username>
    <password>admin123</password>
</server>

进入jar包所在目录运行


mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty

打开cmd直接运行

mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=D:\material\Thirdjar\fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty

猜你喜欢

转载自blog.csdn.net/a954553391/article/details/106791276