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 (mockbuild@kbuilder.bsys.centos.org) (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>
相关推荐
Liii4038 分钟前
【ARM】Cache深度解读
java·arm开发·spring
litGrey44 分钟前
Maven国内镜像(四种)
java·数据库·maven
丶白泽1 小时前
重修设计模式-结构型-桥接模式
java·设计模式·桥接模式
o独酌o1 小时前
递归的‘浅’理解
java·开发语言
无问8171 小时前
数据结构-排序(冒泡,选择,插入,希尔,快排,归并,堆排)
java·数据结构·排序算法
customer082 小时前
【开源免费】基于SpringBoot+Vue.JS在线文档管理系统(JAVA毕业设计)
java·vue.js·spring boot·后端·开源
Flying_Fish_roe2 小时前
Spring Boot-版本兼容性问题
java·spring boot·后端
程序猿进阶2 小时前
如何在 Visual Studio Code 中反编译具有正确行号的 Java 类?
java·ide·vscode·算法·面试·职场和发展·架构
slandarer2 小时前
MATLAB | R2024b更新了哪些好玩的东西?
java·数据结构·matlab
Dola_Pan3 小时前
Linux文件IO(一)-open使用详解
java·linux·dubbo