Maven私服的安装和使用。
(注:原创文章,引用请注明来自Clement-Xu的博客!)
Maven私服(即Repository Manager)的主要作用:
  • 减少从远方仓库下载的次数,节省带宽、提高maven build的效率
  • 减少对远方仓库的依赖,确保maven build的稳定性
  • 方便内部人员发布artifact
  • 方便存放官方仓库中没有的第三方依赖包
Maven官网关于Repository Manager的介绍:https://maven.apache.org/repository-management.html
安装和启动:
2、下载nexus:
wget https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.0.2-02-unix.tar.gz
 
 
3、解压:
tar -zxvf nexus-3.0.2-02-unix.tar.gz
4、创建用户、赋予权限:
# 使用root权限创建一个用户
adduser nexus
 
# 给nexus用户添加sudo权限
1、给root写的权限
chmod u+w /etc/sudoers
2、编辑/etc/sudoers,在root下添加nexus用户权限
vi /etc/sudoers
添加:nexus ALL=(ALL) ALL
3、保存后撤回写的权限
chmod u-w /etc/sudoers
 
修改目录所有者:
chown -R nexus nexus-3.0.2-02
chgrp -R nexus nexus-3.0.2-02
 
5、注册为服务:
ln -s /opt/app/nexus-3.0.2-02 /opt/app/nexus
ln -s /opt/app/nexus/bin/nexus /etc/init.d/nexus
cd /etc/init.d
chkconfig --add nexus
chkconfig --levels 345 nexus on
 
vi /opt/app/nexus/bin/nexus.rc
添加:run_as_user="nexus"
 
6、启动服务:
service nexus start
service nexus status
 
查看运行的log:
tail -f /opt/app/nexus/data/log/nexus.log
看到“Started Sonatype Nexus OSS 3.0.2-02”表示已经启动成功。
 
7、访问:
Sign In,缺省账号密码:admin/admin123
 
注:仓库的不同类型:
  • proxy:代理第三方仓库的
  • hosted:存储本地上传的组建和资源
  • group:一般包含多个proxy仓库和hosted仓库,在项目中一般引入这种类型的仓库就可以下载到proxy和hosted中的包
 
项目中使用:
pom.xml中添加:
  1. <repositories>
  2. <repository>
  3. <id>nexus</id>
  4. <name>Nexus Repository</name>
  5. <url>http://<ip>:8081/repository/maven-public/</url>
  6. </repository>
  7. </repositories>
  8. <pluginRepositories>
  9. <pluginRepository>
  10. <id>nexus</id>
  11. <name>Nexus Plugin Repository</name>
  12. <url>http://<ip>:8081/repository/maven-public/</url>
  13. </pluginRepository>
  14. </pluginRepositories>
 
上传第三方包:
准备工作:
1、需要先配置maven中的setting.xml文件:
  1. <server>
  2. <id>nexus-releases</id>
  3. <username>admin</username>
  4. <password>admin123</password>
  5. </server>
  6. <server>
  7. <id>nexus-snapshots</id>
  8. <username>admin</username>
  9. <password>admin123</password>
  10. </server>
2、创建一个新的repository专门用于存放第三方的jar包:
  1. admin登录nexus,Repositories -> Create repository -> maven2 (hosted)
  2. 填入name:maven-3rd
  3. 选择Blob store:default
  4. 选择Deployment policy:Allow redeploy
  5. 点击:Create repository
3、把新创建的repository加入maven-public group中:
  1. 进入Repositories -> maven-public
  2. 在Group中,加入maven-3rd
  3. 点击:Save
 
万事俱备,可以上传了:
(假设第三方JAR包:taobao-sdk-java-auto_1455552377940-20160330.jar,存放在本地目录D:\3rd_jars\中)
mvn deploy:deploy-file ^
-DgroupId=com.aliyun.api ^
-DartifactId=taobao-sdk-java-auto_1455552377940 ^
-Dversion=2016.03.01 ^
-Dpackaging=jar ^
-Dfile=D:\3rd_jars\taobao-sdk-java-auto_1455552377940-20160330.jar ^
-Durl=http://<ip>:8081/repository/maven-3rd/ ^
-DrepositoryId=nexus-releases
 
注:如果是在linux下运行,需要把连接符“^”替换为“\”
验证结果:在Nexus Search中搜索是否已经上传成功。
 
上传成功后,修改pom.xml中的dependency,指向私服:
<dependency>
<groupId>com.aliyun.api</groupId>
<artifactId>taobao-sdk-java-auto_1455552377940</artifactId>
<version>2016.03.01</version>
</dependency>
 
Deploy jar项目到私服中:
1、pom.xml中的配置:
  1. <distributionManagement>
  2. <repository>
  3. <id>nexus-releases</id>
  4. <name>Nexus Release Repository</name>
  5. <url>http://<ip>:8081/repository/maven-releases/</url>
  6. </repository>
  7. <snapshotRepository>
  8. <id>nexus-snapshots</id>
  9. <name>Nexus Snapshot Repository</name>
  10. <url>http://<ip>:8081/repository/maven-snapshots/</url>
  11. </snapshotRepository>
  12. </distributionManagement>
注意:
  • ID名称必须要与settings.xml中Servers配置的ID名称保持一致。
  • 项目版本号中有SNAPSHOT标识的,会发布到Nexus Snapshots Repository, 否则发布到Nexus Release Repository,并根据ID去匹配授权账号。
2、生成jar包并上传:
> mvn deploy

Maven私服(Repository Manager) - Nexus安装和使用(详细过程)的更多相关文章

  1. (转)搭建Maven私服(使用Nexus)

    搭建私服可以做什么? 1.如果公司开发组的开发环境全部内网,这时如何连接到在互联网上的Maven中央仓库呢? 2.如果公司经常开发一些公共的组件,如何共享给各个开发组,使用拷贝方式吗?如果这样,公共库 ...

  2. 搭建Maven私服(使用Nexus)

    搭建私服能够做什么? 1.假设公司开发组的开发环境所有内网.这时怎样连接到在互联网上的Maven中央仓库呢? 2.假设公司常常开发一些公共的组件.怎样共享给各个开发组.使用拷贝方式吗?假设这样,公共库 ...

  3. Centos7安装jdk-12的详细过程

    Centos7安装jdk-12的详细过程 2019-04-12   21:23:24 一.下载JDK-12版本 链接地址:官方地址 下载:jdk-12_liunx-x64_bin.tar.gz 二.检 ...

  4. docker安装配置gitlab详细过程

    docker安装配置gitlab详细过程   获取镜像 1.方法一 1 docker pull beginor/gitlab-ce:11.0.1-ce.0 2.方法二如果服务器网路不好或者pull不下 ...

  5. VMwear安装Centos7超详细过程

    本篇文章主要介绍了VMware安装Centos7超详细过程(图文),具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.软硬件准备 软件:推荐使用VMwear,我用的是VMwear 12 镜像:Ce ...

  6. VMware安装CentOS7的详细过程

    原文:https://www.jianshu.com/p/ce08cdbc4ddb?utm_source=tuicool&utm_medium=referral 本篇文章主要介绍了VMware ...

  7. 非常详细的 (VMware安装Centos7超详细过程)

    本篇文章主要介绍了VMware安装Centos7超详细过程(图文),具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.软硬件准备 软件:推荐使用VMwear,我用的是VMwear 12 镜像:Ce ...

  8. VMware15安装Centos7超详细过程

    本篇文章主要介绍了VMware安装Centos7超详细过程(图文),具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.软硬件准备 软件:推荐使用VMwear15,我用的是VMwear 15 镜像: ...

  9. VMware安装Centos7超详细过程

    本篇文章主要介绍了VMware安装Centos7超详细过程(图文),具有一定的参考价值,感兴趣的小伙伴们可以参考一下 一.软硬件准备 软件:推荐使用VMwear,我用的是VMwear 12 镜像:Ce ...

  10. VMware 安装 Centos7 超详细过程

    https://www.runoob.com/w3cnote/vmware-install-centos7.html centos7安装参考文档 VMware 安装 Centos7 超详细过程 分类  ...

随机推荐

  1. no such file or directory, open '/node_modules/.staging/

    报错 在使用npm过程中连续产生多行报错 no such file or directory, open '/node_modules/.staging/ 原因 npm版本配置不一致导致,可以尝试重新 ...

  2. [CTSC2017]吉夫特

    Description: 给定一个序列\(a_1,a_2,a_3...a_n\) 求有多少个不上升子序列: \(a_{b1},a_{b_2}...\) 满足 \(C_{a_{b1}}^{a_{b2}} ...

  3. UIAlertController简单使用

    UIAlertView   在iOS2 的时候开始使用,在iOS9 的时候被摒弃 NS_CLASS_DEPRECATED_IOS(2_0, 9_0, "UIAlertView is depr ...

  4. js获取浏览器屏幕的尺寸

    浏览器屏幕尺寸参照表: 如何获取屏幕宽度: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: ...

  5. web界面直连MySql数据库

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  6. 限制标题字符串的长度,超过长度的截取并加上"..."

    /// <summary> /// 限制标题字符串的长度,超过长度的截取并加上"..." /// </summary> /// <param name ...

  7. Java第一课

    1.引入Java虚拟机原因?过程:源文件--编译器(使用javac命令)-----二进制的字节码文件(平台无关)--解释器(使用Java命令)-----可执行文件结论:Java中的跨平台是通过[JVM ...

  8. PHP06

    PHP06 1. 2.可视化工具navicat: 1)查询 : select 字段名1,字段名2- from 表名; 对于可能与关键词重名的名称,建议使用反引号`括起来 可用*通配符代替字段名 sel ...

  9. 虚拟串口VSPD破解版 亲测win10 64可用

    虚拟串口VSPD破解版 亲测win10 64可用 点击下载

  10. 【转】Selenium - 封装WebDrivers (C#)

    本文转载自:http://www.cnblogs.com/qixue/p/3977135.html Web element仍然使用OpenQA.Selenium.IWebElement, 本类库将Se ...