采用Nexus搭建Maven私服

采用Nexus搭建Maven私服

1.采用docker安装

复制代码
1.创建数据目录

挂载的目录:
/usr/local/springcloud_1113/nexus3/nexus-data


2.查询并拉取镜像

docker search nexus3

docker pull sonatype/nexus3


3.查看拉取的镜像

docker images

4.创建docker容器:可能出现启动后停止,可能的原因就是服务器的内存是不足的

docker run -id --privileged=true --name=nexus3 --restart=always -p 58081:8081 -v /usr/local/springcloud_1113/nexus3/nexus-data:/var/nexus-data sonatype/nexus3


5.查看日志

docker logs -f nexus3 

2.访问

复制代码
1.访问地址:http://192.168.101.131:58081/

2.查看默认的密码
docker exec -it 78fa7a779952 bash

bash-4.4$ more nexus-data/admin.password
6fe68b57-20b4-4242-b311-8df8210f1b2b


3.仓库分为发行版和快照版。根据的是版本的后缀进行判断的。不写的话就是默认的发行版。

3.设置阿里云代理

复制代码
https://maven.aliyun.com/repository/central
复制代码
https://maven.aliyun.com/repository/public

4.本地settings.xml设置

复制代码
    <localRepository>D:xxx\apache-maven-3.6.3\repository</localRepository>

    <mirrors>
        <!-- Maven私服配置 -->
        <mirror>
            <id>maven-public</id>
            <name>maven-public</name>
            <url>http://192.168.101.131:58081/repository/maven-public/</url>
            <mirrorOf>*</mirrorOf>
        </mirror>
        <!--阿里云maven库-->
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
		
    </mirrors>

需要和pom中的保持一致  
  <servers>
        <!-- Nexus私服发布的用户名密码 -->
        <server>
            <id>maven-public</id>
            <username>admin</username>
            <password>admin</password>
        </server>
        <server>
            <id>maven-releases</id>
            <username>admin</username>
            <password>admin</password>
        </server>
        <server>
            <id>maven-snapshots</id>
            <username>admin</username>
            <password>admin</password>
        </server>
    </servers>

 <profiles>
        <!-- 配置jdk版本 -->
        <profile>
            <id>jdk1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
            <!-- Nexus私服配置 -->
            <repositories>
                <repository>
                    <id>maven-public</id>
                    <url>http://192.168.101.131:58081/repository/maven-public/</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>maven-releases</id>
                    <url>http://192.168.101.131:58081/repository/maven-releases/</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>

        <!-- 阿里云配置: 提高国内的jar包下载速度 -->
        <profile>
            <id>ali</id>
            <repositories>
                <repository>
                    <id>alimaven</id>
                    <name>aliyun maven</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>alimaven</id>
                    <name>aliyun maven</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

    <!-- 激活配置 -->
    <activeProfiles>
        <activeProfile>jdk1.8</activeProfile>
        <activeProfile>ali</activeProfile>
    </activeProfiles>

5.本地项目创建-并上传

pom中加入

复制代码
    <!--    配置私服仓库-->
    <distributionManagement>
        <!-- 发布版本仓库 -->
        <repository>
            <id>maven-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.101.131:58081/repository/maven-releases/</url>
        </repository>
        <!-- 快照版本仓库 -->
        <snapshotRepository>
            <id>maven-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://192.168.101.131:58081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

编写一点测试代码。代码的打包方式需要时jar的方式。

上传完成

查看

6.下载设置

pom中加入下面的内容

复制代码
 <repositories>
        <repository>
            <id>maven-releases</id>
            <url>http://192.168.101.131:58081/repository/maven-releases/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>

        <repository>
            <id>maven-snapshots</id>
            <url>http://192.168.101.131:58081/repository/maven-snapshots/</url>
        </repository>

    </repositories>

导入依赖

复制代码
      <dependency>
            <groupId>com.lxz.test</groupId>
            <artifactId>demo1116</artifactId>
            <version>1.0.0</version>
        </dependency>

mvn clean package -DskipTests -e -U -X

7.测试

复制代码
    @Test
    void contextLoads() {
        CommonUtils.SayHello("你好!");
    }
相关推荐
猿究院--王升1 小时前
jvm三色标记
java·jvm·算法
妮妮学代码1 小时前
c#:TCP服务端管理类
java·tcp/ip·c#
兔老大RabbitMQ2 小时前
git pull origin master失败
java·开发语言·git
朱皮皮呀2 小时前
Spring Cloud——服务注册与服务发现原理与实现
运维·spring cloud·eureka·服务发现·php
探索java2 小时前
Netty Channel详解:从原理到实践
java·后端·netty
tuokuac3 小时前
maven与maven-archetype-plugin版本匹配问题
java·maven
ankleless4 小时前
Spring Boot 实战:从项目搭建到部署优化
java·spring boot·后端
野生技术架构师4 小时前
2025年中高级后端开发Java岗八股文最新开源
java·开发语言
静若繁花_jingjing5 小时前
JVM常量池
java·开发语言·jvm
David爱编程5 小时前
为什么线程不是越多越好?一文讲透上下文切换成本
java·后端