zoukankan      html  css  js  c++  java
  • Java第四十五天,Maven高级篇(三),私服

    一、安装私服

    1.下载 Nexus

    方法一:到Nexus 官网下载Nexus

    https://www.sonatype.com/

    方法二:我的分享

    https://download.csdn.net/download/ITlanyue/12736638

    2.解压到指定目录(无中文、特殊字符)

    3.安装

    (1)以管理员身份运行 cmd ,进入 nexus 软件的 bin 目录

    (2)运行以下命令

    nexus.bat install

    (3)检查服务是否自动

    4.启动与关闭

    • nexus.bat start ===> 启动服务
    • nexus.bat stop ===> 关闭服务

    5.卸载

    nexus.bat uninstall

    6.修改 nexus 服务端口号

    通过修改软件 /conf/nexus.properties 配置文件的 application-port 键值修改

    7.浏览器访问 nexus UI 界面

    浏览器通过以下路径访问(端口默认为 8081 )

    http://127.0.0.1:8081/nexus/#welcome

    用户名和密码默认如下

    • 用户名:admin
    • 密码:admin123

    8.nexus 仓库种类

    二、本地仓库与私服的上传下载

    1.利用 Maven 项目登录私服

    在 maven 软件的 settings.xml 配置文件中的 <servers/> 标签内部配置如下标签

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

    2.上传本地项目或模块到私服

    (1)在需要上传的子模块的 pom.xml 配置文件中添加如下标签

    <distributionManagement>
        <repository>
            <!--id 和 url 需要核对准确-->
            <id>releases</id>
            <url>http://localhost:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <!--id 和 url 需要核对准确-->
            <id>snapshots</id>
            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

    (2)在需要上传的子模块中运行生命周期中的 deploy 生命周期命令

    3.从私服下载本地所需的工程或模块

    在 maven 的 settings.xml 配置文件中的 <profiles> 标签中添加如下标签

    <!-- 下载jar包配置 -->
    <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>
    
    
    <!--激活下载-->
    <activeProfiles>
        <!--id 需要与上面的 id 对应-->
        <activeProfile>dev</activeProfile>
    </activeProfiles>

    三、上传第三方 jar 包到私服

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

    需要提前知道 第三方 jar包 的坐标

    // 安装第三方jar包到本地仓库
    
    // 方法一:进入jar包所在目录运行
    mvn install:install-file -DgroupId=项目组织名 -DartifactId=项目名 -Dversion=版本号 -Dfile=第三方jar包文件名.jar -Dpackaging=jar
    
    // 方法二:打开cmd直接运行
    mvn install:install-file -DgroupId=项目组织名 -DartifactId=项目名 -Dversion=版本号 -Dpackaging=jar -Dfile=第三方jar包路径+文件名.jar

    2.安装第三方 jar 包到私服

    在 Maven 软件的 settings.xml 配置文件中的 <servers/> 标签中添加如下代码

    <server>
        <!--自己私服的第三方包id-->
        <id>thirdparty</id>
        <!--用户名;默认为 admin-->
        <username>admin</username>
        <!--密码;默认为 admin123-->
        <password>admin123</password>
    </server>

    使用如下命令上传第三方 jar包 到私服

    // 进入jar包所在目录运行
    mvn deploy:deploy-file -DgroupId=第三方jar包项目组织名 -DartifactId=第三方jar包项目名 -Dversion=第三方jar包项目版本号 -Dpackaging=jar -Dfile=第三方jar包文件名.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty
            
    // 打开cmd直接运行
    mvn deploy:deploy-file -DgroupId=第三方jar包项目组织名 -DartifactId=第三方jar包项目名 -Dversion=第三方jar包项目版本号 -Dpackaging=jar -Dfile=第三方jar包路径+文件名.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty
    
  • 相关阅读:
    完全背包
    01背包
    游戏编程:为什么C++游戏开发比Java更好,其实是因为这两个点!
    VS code搭建 C 和 C++ 环境的完整图文教程!赶紧收藏,这波不亏!
    来自清华计算机系的招聘信息,第一个要求就劝退99%的人!网友:但福利待遇真好!
    C++ 必看书籍清单!从C++ Primer 到 源码剖析,精通真的很难!
    C语言简单编程速成!保姆级入门教程, 目标达成!
    9 名程序员被抓!这次是真的活该.....
    你知道各类开发语言的薪酬差距吗?高薪在于适合,而不在于广度!
    apache common包 CollectionUtils 使用 详解
  • 原文地址:https://www.cnblogs.com/viplanyue/p/13573664.html
Copyright © 2011-2022 走看看