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>
    纸上得来终觉浅,绝知此事要躬行。
  • 相关阅读:
    转载: CSS Hack 兼容浏览器经验分享
    PHP parseurl 一个好用的函数
    css 小经验: css hack 的一些兼容小技巧
    jquery 之 $.ajax() 等 success: function(){} 中使return的问题
    转载: PHP socket
    jquery 之 mousedown 鼠标按键响应
    php REMOTEADDR之获取访客IP的代码
    PHP settimelimit0长连接的实现分析
    php selectradio和checkbox默认选择的实现方法
    转载:php 小经验: preg_match 与 preg_match_all 函数
  • 原文地址:https://www.cnblogs.com/boonya/p/14505252.html
Copyright © 2011-2022 走看看