maven私库搭建(nexus)

本文详细介绍如何使用Docker快速搭建Nexus私有仓库服务,包括镜像搜索、拉取、容器创建及网络配置,同时提供了settings.xml配置示例,以便于Maven项目无缝对接私服。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用docker搭建nexus服务

#搜索nexus镜像
docker search nexus

#拉取镜像
docker pull docker.io/sonatype/nexus3

#创建容器
docker run -d -p 8081:8081  --name nexus docker.io/sonatype/nexus3

#查询容器挂载目录文件
docker inspect nexus

#开放端口
firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --zone=public --add-port=8081/udp --permanent
firewall-cmd --reload

#浏览器访问控制台
http://ip:8081

#进入目录查看管理员账号admin的初始密码
cd /var/lib/docker/volumes/4de7569b45a3635a90b783e92b9c533e0976546cedb21749cd6932b4aaf5e657/_data
cat admin.password

在这里插入图片描述在这里插入图片描述

配置settings.xml

<?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">

    <localRepository>E:\plugIn\maven\repository</localRepository>

    <servers>
        <server>
            <id>nexus</id>
            <username>admin</username>
            <password>abc.123</password>
        </server>
    </servers>


    <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.227.133:8081/repository/maven-public/</url>
        </mirror>

<!--  测试时,通过nexus的代理仓库无法连接到中央库.所以这里配置下了中央库地址 -->
<!--     <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        </mirror>


        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>-->
    </mirrors>

    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>maven-public</id>
                    <url>http://192.168.227.133:8081/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>maven-public</id>
                    <url>http://192.168.227.133:8081/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

	#此处必须与profile的id一致
    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>

</settings>

上传工程jar包至私服需要配置pom文件

	#注意distributionManagement中的id名称要与settings.xml文件中server的id名称一致
    <distributionManagement>
        <repository>
            <id>nexus</id>
            <url>http://192.168.227.133:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus</id>
            <url>http://192.168.227.133:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
#使用maven deploy命令上传jar到私服
mvn deploy
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值