zoukankan      html  css  js  c++  java
  • Maven deploy上传jar包到远程仓库

    1. 前言

    Maven 仓库管理也叫 Maven 私服或者代理仓库。使用 Maven 私服有两个目的:

    • 私服是一个介于开发者和远程仓库之间的代理;
    • 私服可以用来部署公司自己的 jar

    2. Nexus 介绍

    Nexus 是一个强大的 Maven 仓库管理工具,使用 Nexus 可以方便的管理内部仓库同时简化外部仓库的访问。

    官网是:www.sonatype.com/

    2.1 Nexus安装

    • 下载

    下载地址:www.sonatype.com/download-os…

    • 解压

    将下载下来的压缩包,拷贝到一个没有中文的路径下,然后解压。

    • 启动

    解压之后,打开 cmd 窗口(以管理员身份打开 cmd 窗口),然后定位了 nexus 解压目录,执行 nexus.exe/run 命令启动服务。这个启动稍微有点慢,大概有 1 两分钟的样子。
    在这里插入图片描述

    启动成功后,浏览器输入 http://lcoalhost:8081 打开管理页面。

    打开管理页面后,点击右上角上的登录按钮进行登录,默认的用户名/密码是 admin/admin123。当然,用户也可以点击设置按钮,手动配置其他用户。
    在这里插入图片描述

    点击 Repositories 可以查看仓库详细信息:
    在这里插入图片描述

    3. 仓库类型

    名称说明
    proxy 表示这个仓库是一个远程仓库的代理,最典型的就是代理 Maven 中央仓库
    hosted 宿主仓库,公司自己开发的一些 jar 存放在宿主仓库中,以及一些在 Maven 中央仓库上没有的 jar
    group 仓库组,包含代理仓库和宿主仓库
    virtual 虚拟仓库

    4. 上传 jar

    上传 jar,配置两个地方:

    Maven 的 conf/settings.xml 文件配置:

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

    在要上传 jar 的项目的 pom.xml 文件中,配置上传路径:

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

    配置完成后,点击 deploy 按钮,或者执行 mvn deploy 命令就可以将 jar 上传到私服上。

    5. 跳过某个module

    I don’t want to deploy one of the artifacts in my multi-module build. Can I skip deployment?
    Yes, you can skip deployment of individual modules by configuring the Deploy Plugin as follows:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.8.2</version>
        <configuration>
            <skip>true</skip>
        </configuration>
    </plugin>

    参考:http://maven.apache.org/plugins/maven-deploy-plugin/faq.html

    6. 下载私服上的 jar

    直接在项目中添加依赖,添加完成后,额外增加私服地址即可:

    <repositories>
        <repository>
            <id>local-repository</id>
            <url>http://localhost:8081/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    纸上得来终觉浅,绝知此事要躬行。
  • 相关阅读:
    HDU 1269 迷宫城堡
    HDU 4771 Stealing Harry Potter's Precious
    HDU 4772 Zhuge Liang's Password
    HDU 1690 Bus System
    HDU 2112 HDU Today
    HDU 1385 Minimum Transport Cost
    HDU 1596 find the safest road
    HDU 2680 Choose the best route
    HDU 2066 一个人的旅行
    AssetBundle管理机制(下)
  • 原文地址:https://www.cnblogs.com/boonya/p/14505252.html
Copyright © 2011-2022 走看看