maven 私服

公司在自己的局域网内搭建自己的远程仓库服务器,称为私服,私服服务器即是公司内部的 maven 远程仓库,
每个员工的电脑上安装 maven 软件并且连接私服服务器,员工将自己开发的项目打成 jar 并发布到私服服务器,
其它项目组从私服服务器下载所依赖的构件(jar)。
私服还充当一个代理服务器,当私服上没有 jar 包会从互联网中央仓库自动下载,如下图:
  

 搭建私服环境:

  Nexus 是 Maven 仓库管理器,通过 nexus 可以搭建 maven 仓库,同时 nexus 还提供强大的仓库管理功能,构件搜索功能等。

  安装 nexus:

    解压 nexus-2.12.0-01-bundle.zip 到指定目录

    使用管理员方式打开 cmd,进入到 bin 目录,执行  nexus.bat install 安装

    安装成功在服务中查看有 nexus 服务

   卸载 nexus:

    管理员 cmd 进入 nexus 的 bin 目录,执行:nexus.bat uninstall

  启动 nexus:

    cmd 进入 bin目录,执行 nexus.bat start 启动,或者到 Windows 服务中,直接启动 nexus 服务

  查看 nexus 的配置文件 conf/nexus.properties:

    # Jetty section
    application-port=8081  # nexus 的访问端口配置
    application-host=0.0.0.0  # nexus 主机监听配置(不用修改)
    nexus-webapp=${bundleBasedir}/nexus  # nexus 工程目录
    nexus-webapp-context-path=/nexus  # nexus 的 web 访问路径
    # Nexus section
    nexus-work=${bundleBasedir}/../sonatype-work/nexus  # nexus 仓库目录
    runtime=${bundleBasedir}/nexus/WEB-INF  # nexus 运行程序目录

  访问:http://localhost:8081/nexus/

    使用 Nexus 内置账户admin/admin123 登陆

仓库类型:

  查看 nexus 的仓库:

  

   nexus 的仓库有 4 种类型:

    

    1. hosted,宿主仓库,部署自己的 jar 到这个类型的仓库,包括 releases 和 snapshot 两部分,Releases公司内部发布版本仓库、 Snapshots 公司内部测试版本仓库
    2. proxy,代理仓库,用于代理远程的公共仓库,如 maven 中央仓库,用户连接私服,私服自动去中央仓库下载 jar 包或者插件。
    3. group,仓库组,用来合并多个 hosted/proxy 仓库,通常我们配置自己的 maven 连接仓库组。
    4. virtual(虚拟):兼容 Maven1 版本的 jar 或者插件

  central :代理仓库,代理中央仓库

    

       

  apache-snapshots :代理仓库

    存储 snapshots 构件,代理地址 https://repository.apache.org/snapshots/
    central-m1 :virtual 类型仓库,兼容 Maven1 版本的 jar 或者插件
    releases : 本地仓库,存储 releases 构件。
    snapshots : 本地仓库,存储 snapshots 构件。
    thirdparty :第三方仓库
    public:仓库组

  nexus 仓库默认在 sonatype-work 目录中:

     

    

猜你喜欢

转载自www.cnblogs.com/roadlandscape/p/12324265.html