centos7安装Nexus(Maven私服)与配置使用教程

之前有位大佬问我,他说有个第三方的Jar包,在idea导出库中使用,现在要部署上线测试,要如何导进去打包。

我说,不用那么麻烦,搞个Nexus私服,将Jar上传上去,然后配置Maven的setting文件指向私服就可以了。

下面介绍Nexus的安装和配置使用。

环境:

bash 复制代码
[root@localhost bin]# java -version
openjdk version "1.8.0_382"
OpenJDK Runtime Environment (build 1.8.0_382-b05)
OpenJDK 64-Bit Server VM (build 25.382-b05, mixed mode)
bash 复制代码
[root@localhost bin]# cat /proc/version
Linux version 3.10.0-1160.71.1.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Tue Jun 28 15:37:28 UTC 2022
1、安装

下载安装包:

下载地址

创建目录:

bash 复制代码
 mkdir nexus

移动压缩包:

bash 复制代码
mv nexus-3.62.0-01-unix.tar.gz  ./nexus

解压:

bash 复制代码
tar -xvf nexus-3.62.0-01-unix.tar.gz

创建目录:

bash 复制代码
mkdir /usr/local/nexus

移动解压后的文件到新建的目录:

bash 复制代码
mv nexus-3.62.0-01 /usr/local/nexus/

切换到bin目录:

bash 复制代码
/usr/local/nexus/nexus-3.62.0-01/bin

编辑配置文件nexus.rc:

powershell 复制代码
run_as_user="root"

启动nexus:

bash 复制代码
./nexus run &

访问:http://192.168.213.5:8081/

登录:

提示登录密码在:/usr/local/nexus/sonatype-work/nexus3/admin.password

点击左侧的browse,有各种repository的type:

  • Group:这是一个仓库聚合的概念,用户仓库地址选择Group的地址,即可访问Group中配置的所有仓库资源,访问顺序取决于配置顺序3.x默认Releases,Snapshots,Central,可在web页面配置在web界面点开
  • Hosted:私有仓库,专门用来存储我们自己生成的jar文件
  • Snapshots:本地项目的快照仓库
  • Releases: 本地项目发布的正式版本
  • Proxy:公网上发布的jar 例如:spring
  • Central:中央仓库

配置maven的setting.xml:

xml 复制代码
在maven的setting.xml文件中配置私服配置,这种方式配置后所有本地使用该配置的maven项目的pom文件都无需配置私服下载相关配置
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    
    <servers>
        <server>
            <id>nexus-releases</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>
    
    <mirrors>
        
        <mirror>
            <id>nexus-releases</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.213.5:8081/content/groups/public/</url>
            <!-- <url>http://repo1.maven.org/maven2/</url> -->
        </mirror>
        <mirror>
            <id>nexus-snapshots</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.213.5:8081/content/repositories/snapshots/</url> 
            <!-- <url>http://repo1.maven.org/maven2/</url> -->
        </mirror>

    </mirrors>

    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>                            
                <repository>
                    <id>nexus-releases</id>
                    <url>http://192.168.213.5:8081/content/groups/public/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
                <repository>
                    <id>nexus-snapshots</id>
                    <url>http://192.168.213.5:8081/content/repositories/snapshots/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus-releases</id>
                    <url>http://192.168.213.5:8081/content/groups/public/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>nexus-snapshots</id>
                <url>http://192.168.213.5:8081/content/repositories/snapshots/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>				
            </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
        <!--<activeProfile>dev</activeProfile>-->
    </activeProfiles>

</settings>
相关推荐
fanged4 小时前
构建系统maven
java·maven
沙滩小岛小木屋4 小时前
maven编译时跳过test过程
java·maven
江沉晚呤时5 小时前
SQL Server 事务详解:概念、特性、隔离级别与实践
java·数据库·oracle·c#·.netcore
还是鼠鼠5 小时前
单元测试-概述&入门
java·开发语言·后端·单元测试·log4j·maven
LB21127 小时前
Maven(黑马)
linux·服务器·maven
MyikJ7 小时前
Java求职面试:从Spring到微服务的技术挑战
java·数据库·spring boot·spring cloud·微服务·orm·面试技巧
MyikJ8 小时前
Java 面试实录:从Spring到微服务的技术探讨
java·spring boot·微服务·kafka·spring security·grafana·prometheus
ShiinaMashirol8 小时前
代码随想录打卡|Day50 图论(拓扑排序精讲 、dijkstra(朴素版)精讲 )
java·图论
cui_hao_nan8 小时前
Nacos实战——动态 IP 黑名单过滤
java
惜.己8 小时前
MySql(十一)
java·javascript·数据库