使用maven,搭建nexus私服

        maven的中央仓库特别的慢,近期为了推动项目转为maven的结构,必须提升下载的速度,摸索着搭建一个私服。将过程记录在此。apache

       一直使用IDEA的maven的插件,并无在系统中安装mavenwindows

一、先安装maven浏览器

        http://maven.apache.org/download.cgi   官网上下载,直接解压后配置环境变量服务器

并在path中增长 %MAVEN_HOME%\binmaven

在cmd 中运行 mvn -version 确认成功。   ide

以前因为在idea中一直使用maven,修改系统中的maven的D:\apache-maven-3.3.9-bin\apache-maven-3.3.9\conf下的settings.xml ,将工具

 <localRepository>C:\Users\Administrator\.m2\repository</localRepository>  修改成原来的maven本地仓库地址。  不然从新下载本地库会疯。url

 

二、安装nexus服务器 idea

    http://www.sonatype.org  在此下载2.X的版本,以前下了最新的3.1,搞了一天没弄明白,资料太少。2.x的资料多一些,反正就是一个工具,能用就行,不必弄得太明白。spa

    下载的.zip版本,直接解压便可。

     解压后存在两个目录以下:

    第一个目录是nexus服务器,第二个目录是资源库的目录。

    运行方式能够配置环境变量,直接命令行执行。请自行百度。

    懒得配,直接执行D:\解压目录\nexus-professional-2.14.1-01\bin\jsw\windows-x86-64\console-nexus.bat   双击后弹出cmd窗体,服务启动:

        

顺利启动后,默认端口是8081,在浏览器上输入http://localhost:8081/nexus

刚进入让你注册,输入邮箱后系统会发给你一个key,输入后则进入welcome界面。

 

点击右上角 Login in  默认用户名 密码   admin   admin123

 

 

这块我也只知其一;不知其二,能够自行百度,都差很少。

添加代理仓库

以 Sonatype 为例,添加一个代理仓库,用于代理 Sonatype 的公共远程仓库。点击菜单 Add - Proxy Repository :

填写Repository ID - sonatype;Repository Name - Sonatype Repository;

Remote Storage Location - http://repository.sonatype.org/content/groups/public/ ,save 保存:

将添加的 Sonatype 代理仓库加入 Public Repositories 仓库组。选中 Public Repositories,在 Configuration 选项卡中,将 Sonatype Repository 从右侧 Available Repositories 移到左侧 Ordered Group Repositories,save 保存:

将右面的都移到左面圆圈处。 表明将选中的库放到public组里。

 

将全部 proxy 类型库 的Download Remote indexes 改成true.

能够在3rd party 中上传已存在的jar

 

三、修改settings.xml 创建私服的镜像

    

<mirrors>
            <mirror>
                <id>central</id>
                <mirrorOf>*</mirrorOf> <!-- * 表示让全部仓库使用该镜像--> 
                <name>central-mirror</name> 
                <url>http://localhost:8081/nexus/content/groups/public/</url>
            </mirror> 
    </mirrors>

 

    

四、验证

mvn help:system

可见确实是从nexus私服进行的下载。

 

 

总结:

       到这里应该就完成了私服的搭建,项目人员只需在项目的pom.xml中添加

<repositories>
    <repository>
        <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
        </releases>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
        </snapshots>
        <id>nexus</id>
        <name>nexus</name>
        <url>http://localhost:8081/nexus/content/groups/public/</url>
        <layout>default</layout>
    </repository>
</repositories>

<pluginRepositories>

    <pluginRepository>
        <id>nexus</id>
        <name>nexus</name>
        <url>http://localhost:8081/nexus/content/groups/public/</url>
    </pluginRepository>

</pluginRepositories>

便可。须要将localhost换成nexus服务器在内网中的地址。

若是添加其余的构件时,会先在nexus私服下载好,之后才会下载到本地。之后,若是发现私服已经存在某一jar包,则会直接从私服下载,若是没有再去代理上下载,代理没有再去中央仓库上下载。

 

在IDEA中进行package操做,截图

速度嗷嗷快啊!!!!!

相关文章
相关标签/搜索