2017-06-28 13:02 844人阅读 评论(0) 收藏 举报
分类:
Maven(1)

版权声明:本文为博主原创文章,未经博主允许不得转载。

一、nexus搭建maven私服及相关介绍

1、下载nexus-2.12.0-01-bundle.zip(版本随意)

2、以管理员身份运行cmd,cd进入解压文件的bin目录,执行nexus.bat install

若未以管理员身份运行则安装不了,因为权限不够


3、开启nexus服务,访问nexus服务器地址:http://localhost:8081/nexus/,默认登录账户为admin,默认密码为admin123,登录成功后点击Repositories可看到私服有以下类型仓库:

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

4、nexus仓库默认在解压文件的sonatype-work\nexus\storage目录中:

apache-snapshots:代理仓库,存储snapshots构件,代理地址https://repository.apache.org/snapshots/

central-m1:virtual类型仓库,兼容Maven1 版本的jar或者插件

releases:本地仓库,存储releases构件。

snapshots:本地仓库,存储snapshots构件。

thirdparty:第三方仓库

public:仓库组

二、向maven私服上传写好的jar

1、需求:将项目子模块ssm_dao这个工程打包成jar并上传到私服

2、第一步:需要在客户端即部署dao工程的电脑上配置 maven环境,并修改 settings.xml 文件,配置连接私服的用户

和密码。此用户名和密码用于私服校验,因为私服需要知道上传都 的账号和密码 是否和私服中的账号和密码 一致。

在maven文件夹下apache-maven-3.5.0\conf\settings.xml文件添加一下代码:(<servers>节点内)

  1. <server>
  2. <!--releases 连接发布版本项目仓库-->
  3. <id>releases</id>
  4. <!--访问releases这个私服上的仓库所用的账户和密码-->
  5. <username>admin</username>
  6. <password>admin123</password>
  7. </server>
  8. <server>
  9. <!--snapshots 连接测试版本项目仓库-->
  10. <id>snapshots</id>
  11. <!--访问releases这个私服上的仓库所用的账户和密码-->
  12. <username>admin</username>
  13. <password>admin123</password>
  14. </server>

3、在ssm_dao的pom.xml文件中添加一下代码:

  1. <!--将ssm_dao上传私服  -->
  2. <distributionManagement>
  3. <!--pom.xml这里<id> 和 settings.xml 配置 <id> 对应  -->
  4. <repository>
  5. <id>releases</id>
  6. <url>http://localhost:8081/nexus/content/repositories/releases/</url>
  7. </repository>
  8. <snapshotRepository>
  9. <id>snapshots</id>
  10. <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
  11. </snapshotRepository>
  12. </distributionManagement>

根据工程的版本号决定上传到哪个宿主仓库,如果版本为release则上传到私服的release仓库,如果版本为snapshot则上传到私服的snapshot仓库。

如:ssm_dao的工程的版本号为0.0.1-SNAPSHOT,则ssm_dao打包好的jar在本地仓库snapshots可见

  1. <modelVersion>4.0.0</modelVersion>
  2. <parent>
  3. <groupId>com.nocol</groupId>
  4. <artifactId>ssm_parent</artifactId>
  5. <version><span style="color:#FF0000;">0.0.1-SNAPSHOT</span></version>
  6. </parent>
  7. <artifactId>ssm_dao</artifactId>

4、正式上传:首先启动nexus服务,对ssm_dao工程执行deploy命令,看到BUILD SUCCESS则表示上传成功了

此时在\nexus-2.12.0-01-bundle\sonatype-work\nexus\storage\snapshots下能找到,但是在本地仓库并没有,因为jar包上传在maven私服,接下来介绍如何能让自己上传的jar出现在本地仓库

如图:(本地snapshots)

如图:(私服)

5、此时将ssm_dao工程关闭,可以看到依赖ssm_dao的ssm_service工程出现感叹号(缺少了ssm_dao.jar)

三、maven私服自动下载jar包
1、在没有配置nexus之前,如果本地仓库没有,去中央仓库下载。有了私服之后,本地项目首先去本地仓库找jar,如果没有找到则连接私服从私服下载jar包,如果私服没有jar包私服同时作为代理服务器从中央仓库下载jar包,这样提高了下载速度,项目连接私服下载jar包的速度要比项目连接中央仓库的速度快的多。

2、nexus中包括很多仓库,如上面介绍的hosted中存放的是自己发布的jar包及第三方公司的jar包,proxy中存放的是中央仓库的jar,为了方便从私服下载jar包可以将多个仓库组成一个仓库组,每个工程需要连接私服的仓库组下载jar包,这样在项目中配置下载路径只需要给仓库组路径即可,即:

http://localhost:8081/nexus/content/groups/public/

3、第一步:在客户端的setting.xml中配置私服的仓库,由于setting.xml中没有repositories的配置标签需要使用profile定义仓库(profile节点内)

  1. <profile>
  2. <!--profile的id-->
  3. <id>dev</id>
  4. <repositories>
  5. <repository>
  6. <!--仓库id,repositories可以配置多个仓库,保证id不重复-->
  7. <id>nexus</id>
  8. <!--仓库地址,即nexus仓库组的地址-->
  9. <url>http://localhost:8081/nexus/content/groups/public/</url>
  10. <!--是否下载releases构件-->
  11. <releases>
  12. <enabled>true</enabled>
  13. </releases>
  14. <!--是否下载snapshots构件-->
  15. <snapshots>
  16. <enabled>true</enabled>
  17. </snapshots>
  18. </repository>
  19. </repositories>
  20. <pluginRepositories>
  21. <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
  22. <pluginRepository>
  23. <!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
  24. <id>public</id>
  25. <name>Public Repositories</name>
  26. <url>http://localhost:8081/nexus/content/groups/public/</url>
  27. </pluginRepository>
  28. </pluginRepositories>
  29. </profile>

使用profile定义仓库需要激活才可生效,再在profile结束标签后添加一下代码:

  1. <!--使用profile定义仓库需要激活才可生效-->
  2. <activeProfiles>
  3. <activeProfile>dev</activeProfile>
  4. </activeProfiles>

4、配置成功后通过eclipse查看ssm_service工程下pom.xml的Effective POM选项,可看到如下代码:

  1. <repositories>
  2. <repository>
  3. <releases>
  4. <enabled>true</enabled>
  5. </releases>
  6. <snapshots>
  7. <enabled>true</enabled>
  8. </snapshots>
  9. <id>nexus</id>
  10. <url>http://localhost:8081/nexus/content/groups/public/</url>
  11. </repository>
  12. <repository>
  13. <snapshots>
  14. <enabled>false</enabled>
  15. </snapshots>
  16. <id>central</id>
  17. <name>Central Repository</name>
  18. <url>https://repo.maven.apache.org/maven2</url>
  19. </repository>
  20. </repositories>
  21. <pluginRepositories>
  22. <pluginRepository>
  23. <id>public</id>
  24. <name>Public Repositories</name>
  25. <url>http://localhost:8081/nexus/content/groups/public/</url>
  26. </pluginRepository>
  27. <pluginRepository>
  28. <releases>
  29. <updatePolicy>never</updatePolicy>
  30. </releases>
  31. <snapshots>
  32. <enabled>false</enabled>
  33. </snapshots>
  34. <id>central</id>
  35. <name>Central Repository</name>
  36. <url>https://repo.maven.apache.org/maven2</url>
  37. </pluginRepository>
  38. </pluginRepositories>

表示当该工程需要的jar在本地仓库没有时,根据这里配置的访问路径自动去maven私服下载。此时再update一下父工程,发现ssm_service的感叹号消失(此时ssm_dao还是close状态),说明ssm_service工程已经在maven私服内下载了ssm_dao.jar,同时在本地仓库也存在了该jar。

nexus搭建maven私服及私服jar包上传和下载的更多相关文章

  1. nexus的jar包上传与下载

    1. hosted,宿主仓库,部署自己的jar到这个类型的仓库,包括releases和snapshot两部分,Releases公司内部发布版本仓库. Snapshots 公司内部测试版本仓库 2. p ...

  2. Maven中安装本地Jar包到仓库中或将本地jar包上传

    摘要 maven install 本地jar 命令格式 mvn install:install-file -DgroupId=<group_name> -DartifactId=<a ...

  3. 用eclipse怎样将本地的项目打成jar包上传到maven仓库

    使用maven的项目中,有时需要把本地的项目打成jar包上传到mevan仓库. 操作如下: 前提:pom文件中配置好远程库的地址,否则会报错 1.将maven 中的settings文件配置好用户名和密 ...

  4. maven jar包上传到服务器

    maven jar包上传到服务器时出现pom文件没有上传上去,致使该jar包再被使用的时候没有依赖,jar包调用出错 解决办法,将pom文件一起deploy上去 mvn deploy:deploy-f ...

  5. 构建自己的jar包上传至Mvaen中央仓库和版本更新

    构建自己的jar包上传至Mvaen中央仓库和版本更新 一直羡慕别人制造轮子,开源项目,供别人使用:我也想这样,可以自己才疏学浅,本次就将自己写小工具上传到Maven的中央仓库. 一步一步详细教程演示如 ...

  6. Apache Flink任意Jar包上传导致远程代码执行漏洞复现

    0x00 简介 Apache Flink是由Apache软件基金会开发的开源流处理框架,其核心是用Java和Scala编写的分布式流数据流引擎.Flink以数据并行和流水线方式执行任意流数据程序,Fl ...

  7. IDEA如何将写好的java类(UDF函数)打成jar包上传linux

    一.编写一个UDF函数,实现将字符串大写转小写 import org.apache.hadoop.hive.ql.exec.UDF; import org.apache.hadoop.io.Text; ...

  8. Apache Flink Dashboard未授权访问导致任意Jar包上传漏洞

    漏洞危害 攻击者无需Flink Dashboard认证,通过上传恶意jar包 csdn-[漏洞复现]Apache Flink任意Jar包上传导致远程代码执行 freebuf-Apache Flink ...

  9. 使用mvn deploy命令将本地jar包上传到maven私服

    记录一下,以后少走弯路 前提:已经搭建好nexus maven私服,地址192.168.110.240:9091 在maven的setting.xml中找到<mirrors></mi ...

随机推荐

  1. CodeForces 702B Powers of Two【二分/lower_bound找多少个数/给出一个数组 求出ai + aj等于2的幂的数对个数】

    B. Powers of Two   You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i,  ...

  2. 大型网站优化-memcache技术

    大型网站优化-memcache技术 memory+cache 内存缓存 memcache简介 memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发 ...

  3. apache2.4+tomcat8+jk1.2.40集群配置

    由于目前很多apache+tomcat集群都是在apache2.2上配置的,Apache2.4的教程几乎没有,这里写一篇记录下来. 环境:apache2.4.12(Apache Haus编译版本).t ...

  4. Java线程池ThreadPoolExecutor类源码分析

    前面我们在java线程池ThreadPoolExecutor类使用详解中对ThreadPoolExector线程池类的使用进行了详细阐述,这篇文章我们对其具体的源码进行一下分析和总结: 首先我们看下T ...

  5. Code signing is required for product type Unit Test Bundle in SDK iOS 8.0

    I fixed the issue (temporarily) by going to Edit Scheme, then in the Build section, removing my unit ...

  6. cordova热更新插件调试

    有更新www目录内容后,首先sencha app build,然后进入 cordova目录 运行 cordova-hcp build, 然后查看 chcp.json文件时间,然后压缩cordova目录 ...

  7. CEF生成JSON数据

    在"使用CEF的JSON解析功能"中介绍了使用CefParseJson方法,与之相应的另一个CefWriteJson方法,能够用来生成JSON串(或二进制),其函数原型例如以下: ...

  8. sublimetext3打造pythonIDE

    虽然pycharm是非常好用的pythonIDE,用来开发项目很方便,但是修改调整单个或几个小程序就显得很笨重,这时候我们可以选择使用sublime. 一般来说要开发项目我都用pycharm,开发简单 ...

  9. BF3 里面的z cull reverse reload

    Bf3 siggraph2011的 分享 http://advances.realtimerendering.com/s2011/White,%20BarreBrisebois-%20Renderin ...

  10. 如何查看linux版本 如何查看LINUX是多少位

    一.如何得知自己正在使用的linux是什么版本呢,下面的几种方法将给你带来答案! 1. 查看内核版本命令: 1) [root@q1test01 ~]# cat /proc/version Linux ...