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>
相关推荐
Maynor99614 分钟前
AI Coding 零基础实战教程|第五部分:完整项目案例实操
java·前端·人工智能·claude code·ai coding
生戎马30 分钟前
Tomcat Container容器之Engine:StandardEngine _
java·tomcat
zhangjw3444 分钟前
第29篇:Java伪共享与对象分配:并发性能优化的关键
java·开发语言·性能优化
宠友信息1 小时前
内容社区源码多端数据协议与 Spring Boot 状态流转实现思路
java·spring boot·websocket·uni-app
一路向北North2 小时前
Spring Security OAuth2.0(19):JWT令牌
java·后端·spring
玛卡巴卡ldf2 小时前
【LeetCode 手撕算法】(细节知识点总结)
java·数据结构·算法·leetcode·力扣
一叶飘零_sweeeet2 小时前
IDEA 插件 Trae AI 最新全攻略(基于 TRAE AI: Coding Assistant 1.7.0.0)
java·intellij-idea·trae
KobeSacre3 小时前
CyclicBarrier 源码
java·jvm·算法
MacroZheng3 小时前
给Claude Code装上这款炫酷的HUD插件,状态信息就一目了然了!
java·人工智能·后端
我登哥MVP3 小时前
Hadoop成长史-从Nutch子项目到大数据生态王者
java·大数据·hadoop·分布式·云原生·云计算