nexus搭建maven私服及私服jar包上传和下载
来源:互联网 发布:中国原油进口数据 编辑:程序博客网 时间:2024/06/03 23:31
一、nexus搭建maven私服及相关介绍
1、下载nexus-2.12.0-01-bundle.zip(版本随意)
若未以管理员身份运行则安装不了,因为权限不够
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目录中:
此时在\nexus-2.12.0-01-bundle\sonatype-work\nexus\storage\snapshots下能找到,但是在本地仓库并没有,因为jar包上传在maven私服,接下来介绍如何能让自己上传的jar出现在本地仓库
三、maven私服自动下载jar包
1、在没有配置nexus之前,如果本地仓库没有,去中央仓库下载。有了私服之后,本地项目首先去本地仓库找jar,如果没有找到则连接私服从私服下载jar包,如果私服没有jar包私服同时作为代理服务器从中央仓库下载jar包,这样提高了下载速度,项目连接私服下载jar包的速度要比项目连接中央仓库的速度快的多。
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目录中:
central-m1:virtual类型仓库,兼容Maven1 版本的jar或者插件
releases:本地仓库,存储releases构件。
snapshots:本地仓库,存储snapshots构件。
thirdparty:第三方仓库
public:仓库组
1、需求:将项目子模块ssm_dao这个工程打包成jar并上传到私服
2、第一步:需要在客户端即部署dao工程的电脑上配置 maven环境,并修改 settings.xml 文件,配置连接私服的用户
和密码。此用户名和密码用于私服校验,因为私服需要知道上传都 的账号和密码 是否和私服中的账号和密码 一致。
在maven文件夹下apache-maven-3.5.0\conf\settings.xml文件添加一下代码:(<servers>节点内)<server> <!--releases 连接发布版本项目仓库--> <id>releases</id> <!--访问releases这个私服上的仓库所用的账户和密码--> <username>admin</username> <password>admin123</password> </server><server><!--snapshots 连接测试版本项目仓库--> <id>snapshots</id> <!--访问releases这个私服上的仓库所用的账户和密码--> <username>admin</username> <password>admin123</password> </server>3、在ssm_dao的pom.xml文件中添加一下代码:
<!--将ssm_dao上传私服 --> <distributionManagement> <!--pom.xml这里<id> 和 settings.xml 配置 <id> 对应 --> <repository> <id>releases</id><url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots</id><url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
根据工程的版本号决定上传到哪个宿主仓库,如果版本为release则上传到私服的release仓库,如果版本为snapshot则上传到私服的snapshot仓库。
如:ssm_dao的工程的版本号为0.0.1-SNAPSHOT,则ssm_dao打包好的jar在本地仓库snapshots可见 <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.nocol</groupId> <artifactId>ssm_parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <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)
如图:(私服)
三、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节点内)
<profile> <!--profile的id--> <id>dev</id> <repositories> <repository> <!--仓库id,repositories可以配置多个仓库,保证id不重复--> <id>nexus</id> <!--仓库地址,即nexus仓库组的地址--> <url>http://localhost:8081/nexus/content/groups/public/</url> <!--是否下载releases构件--> <releases> <enabled>true</enabled> </releases> <!--是否下载snapshots构件--> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 --> <pluginRepository> <!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 --> <id>public</id> <name>Public Repositories</name> <url>http://localhost:8081/nexus/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile>使用profile定义仓库需要激活才可生效,再在profile结束标签后添加一下代码:
<!--使用profile定义仓库需要激活才可生效--> <activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles>4、配置成功后通过eclipse查看ssm_service工程下pom.xml的Effective POM选项,可看到如下代码:
<repositories> <repository> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> <id>nexus</id> <url>http://localhost:8081/nexus/content/groups/public/</url> </repository> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>public</id> <name>Public Repositories</name> <url>http://localhost:8081/nexus/content/groups/public/</url> </pluginRepository> <pluginRepository> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> </pluginRepository> </pluginRepositories>表示当该工程需要的jar在本地仓库没有时,根据这里配置的访问路径自动去maven私服下载。此时再update一下父工程,发现ssm_service的感叹号消失(此时ssm_dao还是close状态),说明ssm_service工程已经在maven私服内下载了ssm_dao.jar,同时在本地仓库也存在了该jar。
阅读全文
0 0
- nexus搭建maven私服及私服jar包上传和下载
- Nexus搭建Maven私服上传与下载项目
- nexus 私服上传本地jar包
- Maven客户端只能通过Nexus私服下载Jar包构件
- 使用Nexus搭建Maven私服托管Android aar或jar包
- Maven及Nexus私服搭建
- maven上传jar到nexus私服仓库
- maven私服的搭建及jar包上传下载
- maven和私服nexus搭建教程
- Nexus私服无法下载SNAPSHOT版本的jar包
- Nexus私服修改构件(Jar包)下载文件夹路径
- maven jar包上传私服
- Maven私服上传 jar包
- maven上传私有jar包到本地私服仓库,私服使用nexus repository manager 3.3
- Maven+Nexus私服搭建
- maven搭建私服nexus
- Maven Nexus私服搭建
- maven nexus 搭建私服
- Python库资源大全
- 10张图带你深入理解Docker容器和镜像
- shell批量处理--统计和判断
- Html常用标签元素
- 微信emoji表情编码的处理与储存
- nexus搭建maven私服及私服jar包上传和下载
- android 6.0 SystemUI源码分析(1)-SystemUI介绍
- A child container failed during start java.util.concurrent.ExecutionException异常解决
- cf 421 (2 of 5)
- 各大公司后端java面试题总结
- 多线程——————停止线程
- 在shiro当设置sessionIdCookie配置的domain和访问url不匹配时,每次请求都会重新生成session
- HTML 标签解释大全
- 学习Linux命令(51)