docker怎么搭建maven私有仓库以及使用-成都快上网建站

docker怎么搭建maven私有仓库以及使用

这篇文章主要介绍“docker怎么搭建maven私有仓库以及使用”,在日常操作中,相信很多人在docker怎么搭建maven私有仓库以及使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”docker怎么搭建maven私有仓库以及使用”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

创新互联建站10多年企业网站设计服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,企业网站设计及推广,对楼梯护栏等多个方面拥有丰富的网站推广经验的网站建设公司。

maven私有仓库一般是企业为你建立项目管理而构建的来存储maven项目开发中的依赖jar文件和jar文件的管理,提高工作效率。下面就使用Doker来搭建maven私有仓库并使用,步骤如下:

使用docker安装Nexus

  1. 通过Docker search nexus 命令,搜索nexus镜像,先择合适的镜像,如:docker.io/sonatype/nexus3
    如图所示:

docker怎么搭建maven私有仓库以及使用

  1. 拉取Nexus镜像,执行命令:docker pull docker.io/sonatype/nexus3 ,如下图所示:

docker怎么搭建maven私有仓库以及使用

  1. 创建仓库,并给仓库文件夹权限,命令如下:

    mkdir -p /usr/local/nexus3/nexus-data
    chown -R 200 /usr/local/nexus3/nexus-data
  2. Nexus创建容器,并启动,命令如下:

docker run -tid -p 8081:8081 --name nexus -e NEXUS_CONTEXT=nexus -v /usr/local/nexus3/nexus-data:/nexus-data -d docker.io/sonatype/nexus3

通过docker ps 查看Nexus是否启动成功(注:若正常启动,则代表Nexus安装成功)
注:docker 的使用和常用命令,后续会文章中会有详细讲解。

Nexus的配置

  1. 登录nexus(注:访问:http://ip:8081/nexus 使用默认管理员身份登录,帐号:admin,密码:admin123)如下图所示:

docker怎么搭建maven私有仓库以及使用

  1. 进入管理界面,如下图所示:

docker怎么搭建maven私有仓库以及使用

Browse可以查看当前有多少仓库,搭建好的Nexus,默认会带有一些maven仓库,一般使用这些仓库就足够了。
i. 默认仓库说明:

maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar

maven-releases:私库发行版jar,初次安装请将Deployment policy设置为Allow redeploy

maven-snapshots:私库快照(调试版本)jar

maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml或项目pom.xml中使用

ii. 仓库类型

Group:这是一个仓库聚合的概念,用户仓库地址选择Group的地址,即可访问Group中配置的,用于方便开发人员自己设定的仓库。maven-public就是一个Group类型的仓库,内部设置了多个仓库,访问顺序取决于配置顺序,3.x默认Releases,Snapshots,                             Central,当然你也可以自己设置。

Hosted:私有仓库,内部项目的发布仓库,专门用来存储我们自己生成的jar文件

3rd party:未发布到公网的第三方jar (3.x去除了)

Snapshots:本地项目的快照仓库

Releases: 本地项目发布的正式版本

Proxy:代理类型,从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage属性的值即被代理的远程仓库的路径),如可配置阿里云maven仓库

Central:中央仓库

Apache Snapshots:Apache专用快照仓库(3.x去除了)
  1. 新增代理源,操作如下:
    (1). 按照步骤添加新的代理源

docker怎么搭建maven私有仓库以及使用

(2). 选择添加的代理,如maven2

docker怎么搭建maven私有仓库以及使用

(3). 添加代理(Cache统一设置为200天 288000)

docker怎么搭建maven私有仓库以及使用

docker怎么搭建maven私有仓库以及使用

(4). 逐个增加常用代理

1. aliyun
http://maven.aliyun.com/nexus/content/groups/public
2. apache_snapshot
https://repository.apache.org/content/repositories/snapshots/
3. apache_release
https://repository.apache.org/content/repositories/releases/
4. atlassian
https://maven.atlassian.com/content/repositories/atlassian-public/
5. central.maven.org
http://central.maven.org/maven2/
6. datanucleus
http://www.datanucleus.org/downloads/maven2
7. maven-central (安装后自带,仅需设置Cache有效期即可)
https://repo1.maven.org/maven2/
8. nexus.axiomalaska.com
http://nexus.axiomalaska.com/nexus/content/repositories/public
9. oss.sonatype.org
https://oss.sonatype.org/content/repositories/snapshots
10.pentaho
https://public.nexus.pentaho.org/content/groups/omni/

(5). 设置maven-public 将这些代理加入Group,最好将默认的maven库放到最底下

docker怎么搭建maven私有仓库以及使用

(6).设置私用仓库可重复发布(注:Nexus安装后自带maven-releases,maven-snapshots两个仓库,用于将生成的jar包发布在这两个仓库中,在实际开发中需要将maven-releases设置为可以重复发布)

docker怎么搭建maven私有仓库以及使用

配置maven,使用Nexus

修改本机下的.m2下面的setting.xml文件配置,图下:







  
  ${user.home}/.m2/repository

  

  

  
  
    
  

  
  
    
  

  
  
    
    
    
      releases
      admin
      admin23
    
    
    
      snapshots
      admin
      admin123
    

    
  

  
  
    
    
      HolliParkMirror
      *
      HolliPark Repository Mirror.
      http://localhost:8082/nexus/repository/maven-public/
    
       
  

  
  
    
      HolliPark
      
        
          nexus
          Public Repositories
          http://localhost:8082/nexus/repository/maven-public/
          
            true
          
        
      
        
          central
          Central Repositories
          http://localhost:8082/nexus/repository/maven-central/
          
            true
          
          
            false
          
        
        
        
          release
          Release Repositories
          http://localhost:8082/nexus/repository/maven-releases/
          
            true
          
          
            false
          
        
        
        
          snapshots
          Snapshot Repositories
          http://localhost:8082/nexus/repository/maven-snapshots/
          
            true
          
          
            true
          
        
      
      
      
        
          plugins
          Plugin Repositories
          http://localhost:8082/nexus/repository/maven-public/
        
      
    
    
    
    
  

  
  
  
    HolliPark
  
  

创建Maven私有仓库,步骤如下:

(1).创建maven项目

docker怎么搭建maven私有仓库以及使用

(2).修改pom.xml(注: 在pom文件中加入distributionManagement节点,注意:pom.xml中repository里的id需要和.m2中setting.xml里的server id名称保持一致)

(3). 发布私有库到私有仓库中,命令:mvn deploy
再次登录Nexus,就可看到对应仓库已经有相关依赖包

到此,关于“docker怎么搭建maven私有仓库以及使用”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


网页标题:docker怎么搭建maven私有仓库以及使用
URL网址:http://kswjz.com/article/ijcisg.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流