使用Nexus3搭建Maven私服

1. 私服简介

私服是指私有服务器,是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构建。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
这里写图片描述

2. nexus3的环境安装

nexus3的下载地址:https://www.sonatype.com/download-oss-sonatype
这里写图片描述

这里我下载的是zip包,解压如下:
这里写图片描述

打开bin/nexus.vmoptions文件,配置一下-Dkaraf.data和-Djava.io.tmpdir这两个参数,其他参数可以根据需要进行配置。
这里写图片描述

打开etc/org.sonatype.nexus.cfg这个文件
这里写图片描述
这里可以根据需要来配置nexus-context-path这个参数,这个是nexus启动时的根路径,默认是“/”。

3. nexus3的启动

配置完成后,cmd打开远程客户端,进入nexus-3.0.1-01\bin下。这里可以在环境变量里把nexus配置path,这样就不需要在每次启动的时候,还要进入nexus目录下。接下来执行命令:nexus.exe /run。
当看到如下界面时,即为启动成功。
这里写图片描述

启动成功后,访问:localhost:8081。
默认的用户名和密码:admin/admin123,登录后看到如下图所示:
这里写图片描述

4. component的介绍

component name的一些说明:
- maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar
- maven-releases:私库发行版jar
- maven-snapshots:私库快照(调试版本)jar
- maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。

component type的一些说明:
- hosted:类型的仓库,内部项目的发布仓库
- releases:内部的模块中release模块的发布仓库
- snapshots:发布内部的SNAPSHOT模块的仓库
- 3rd party:第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去
- proxy:类型的仓库,从远程中央仓库中寻找数据的仓库
这里写图片描述

5. settings.xml配置

这里提供下settings.xml的配置,如下:

<?xml version="1.0" encoding="UTF-8"?>
<settings>
    <localRepository>D:\JWCMS_HOME\maven_repository</localRepository>

    <pluginGroups>
        <pluginGroup>org.sonatype.plugins</pluginGroup>
    </pluginGroups>

    <servers>
        <server>
            <id>nexus</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>

    <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://localhost:8081/repository/maven-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>central</id>
                    <url>http://central</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>http://central</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>
</settings>

6. pom.xml配置

这里提供下pom.xml的配置,如下:

<distributionManagement>
    <repository>
        <id>nexus</id>
        <name>Releases</name>
        <url>http://localhost:8081/repository/maven-releases</url>
    </repository>
    <snapshotRepository>
        <id>nexus</id>
        <name>Snapshot</name>
        <url>http://localhost:8081/repository/maven-snapshots</url>
    </snapshotRepository>
</distributionManagement>

7.发布

最后在eclipse中,打开Run/Run Configurations…,界面如下:
这里写图片描述
配置好相关参数,执行run。

当在eclipse的console里看到如下内容时,即为本地工程已经上传到私服成功。
这里写图片描述

注意:它在上传的过程中,如果私服有jar包,则使用私服上的jar包。如果私服没有jar,它会去远程仓库拉取,并放到私服仓库中。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值