zoukankan      html  css  js  c++  java
  • Docker之Nexus搭建Maven仓库

     Maven公服 http://maven.aliyun.com 

    1. https://hub.docker.com 搜索nexus

    2. docker pull sonatype/nexus3

    3. 创建Docker目录,创建nexus目录

        cd /usr/local/
        mkdir docker 
        cd docker/
        mkdir nexus
        cd nexus/
        vi docker-compose.yml

    4. 使用Docker来安装和运行Nexus,docker-compose.yml配置如下:

        version:'3.1'
        services:
            nexus:
                restart:always
                image:sonatype/nexus3
                container_name:nexus
                ports:
                    -8081:8081
                volumes:
                    - /usr/local/docker/nexus/data:/nexus-data
       

    5. docker-compose up -d

    6. 访问http://ip:8081

    7. 看日志

        docker ps 
        docker logs containerID

    8. 如果报错没权限 查看data中是否有数据,让data有所有权限

        cd /data/
        ll
        docker-compose down
        chmod 777 data/

    9. docker-compose -up -d


    10. 启动nexus耗内存,看内存状态,nexus的启动需要耗费近1G内存;

        free -h
        htop

    11. 登陆nexus,默认用户名`admin`密码`admin123`

    12. 在Maven setting.xml中添加Nexus认证信息(servers节点下)

        <server>
            <id>nexus-releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>

    13. 把项目和私服关联起来,在pom.xml添加配置

    <distributionManagement>
            <repository>
                <id>nexus-releases</id>
                <name>Nexus Release Repository</name>
                <url>http://192.168.0.148:8081/repository/maven-releases/</url>
            </repository>
            <snapshotRepository>
                <repository>
                    <id>nexus-snapshots</id>
                    <name>Nexus Snapshot Repository</name>
                    <url>http://192.168.0.148:8081/repository/maven-snapshots/</url>
                </repository>
            </snapshotRepository>
        </distributionManagement>

    注:ID与setting.xml中Servers配置的一致
    url地址与私服仓库地址一致


    14. mvn deploy -Dmaven.test.skip=true

    15. 项目需要依赖先去本地找,本地没有去私服(内网)找,私服没有去官服找;
    第三方依赖或者自己写的jar,可以手动上传到私服,3.13版本nexus支持上传功能

    16. 配置代理仓库,目的是使项目走私服下载依赖到本地仓库
     

       <repositories>
            <repository>
                <id>nexus</id>
                <name>Nexus Repository</name>
                <url>http://192.168.0.148:8081/repository/maven-public/</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
        <repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>nexus</id>
                <name>Nexus Repository</name>
                <url>http://192.168.0.148:8081/repository/maven-public/</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </pluginRepository>
        </pluginRepositories>

    17. 到这里项目就可以从私服到本地仓库了

    1、SNAPSHOT版本代表不稳定(快照版本),还在处于开发阶段,随时都会有变化。当上传同样的版本号jar包的时候,SNAPSHOT会在版本号的后面自动追加一串新的数字,即日志标签;

    2、RELEASE则代表稳定的版本(发布版本),一般上线后都会改用RELEASE版本。

    在maven的依赖管理机制中,唯一标识一个依赖项是由该依赖项的三个属性构成的,分别是groupId、artifactId以及Version。这三个属性唯一确定一个组件(即我们平时说的war包和jar包)。

    3. 仓库中public是集合了快照版和发行版的映射

  • 相关阅读:
    无线鼠标换电池了
    Jython Interactive Servlet Console YOU WILL NEVER KNOW IT EXECLLENT!!! GOOD
    Accessing Jython from Java Without Using jythonc
    jython podcast cool isnt't it?
    Python里pycurl使用记录
    Creating an Interactive JRuby Console for the Eclipse Environment
    微软为AJAX和jQuery类库提供CDN服务
    Download A File Using Cygwin and cURL
    What is JMRI?这个是做什么用的,我真没看懂但看着又很强大
    用curl 发送指定的大cookie的http/https request
  • 原文地址:https://www.cnblogs.com/cgy-home/p/11238380.html
Copyright © 2011-2022 走看看