maven nexus私服搭建

本文介绍如何使用Maven Nexus搭建私有仓库,包括私服的重要性、环境搭建步骤、配置远程代理及本地仓库的方法,帮助解决大型团队协作时的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Maven Nexus


1、简介:是开源的,用该框架架设maven私有服务器


2、关于中央仓库注意事项:
   地址:目前来说:http://repol.maven.org/maven2/是真正的maven中央  仓库的地址,该地址内置在maven的源码中 其他的都是镜像
   索引:中央仓库带有索引文件以方便用户对其搜索,完整的索引文件大小为60M,索引每周更新一次
   黑名单:如果某个IP地址恶意的下载中央仓库内容,例如全公司100台机器使用一个IP反复下载,这个IP会进入黑名单,因此,稍有规    模的使用maven时,应该使用Nexus架                   设私服


3、为什么要使用nexus私服
   1、开发人员过多,是公司IP地址被记录黑名单,无法下载
   2、有些项目为了保密,没有外网,不能远程访问仓库地址,只能在局域网搭建nexus服务器,开发人员连接这台服务器
   3、自己写的jar包,可以上传到私服供别人使用



4、可以通过设置镜像方法;将远程仓库的请求转到nexus私服上对应的镜像中


5、nexus私服环境搭建
   把nexus.war包放到tomcat的webapps下面(war包可在tomcat中直接运行)
   浏览
   用户名:admin
   密码:admin123

   这里单独专门用一个tomcat用于运行maven nexus私服
   后边还会搭设专门的图片服务器、应用服务器等


   1>拷贝下载好的nexus的war包,黏贴到tomcat安装目录(全新的tomcat)   --> webapps


   2>启动部署好的tomcat,bin --> startup  时间有点长


   3>浏览器localhost:8080/nexus-2.9.0运行私服项目


   4>账号密码登录(右上角login in)
     Repositories:
                 Type:(仓库类型)
                    group:组 
                    hosted:
                    proxy:代理
                    virtual:虚拟机


     hosted:宿主仓库,该仓库属于公司私有的,内部项目的发布仓库,发布一些第三方不允许的组件,比如oracle驱动,商业软件jar包
            1)3rd part:第三方依赖的仓库,这个数据通常是由内部人员自行下载后发布上去
            2)snapshot:测试版本、镜像版本  发布内部的SNAPSHOP模块的仓库
            3)release:发行的版本
     proxy:代理仓库,  从远程中央仓库中寻找数据的仓库
           proxy 代表代理远程的仓库,最典型的就是maven中央仓库、JBoss仓库等等。
           如果构建的maven项目本地仓库没有依赖包,那么就会去这个代理站点去下载,如果代理站点也没有此依赖包,就会去远程 
          中央仓库去下载依赖,这些中央仓库就是proxy。代理站点下载成功后再下载至本机。
     group:仓库组 虚拟的概念,可以包含其他的仓库 ,组仓库用来方便 


          开发人员进行设置的仓库           
             
           这里主要分为hosted和proxy
           
     5>设置远程代理
       
       方法一(慢):
       开启代理: 
       选中代理仓库 --> Configuration --> Download Remota Indexes --> true 
       
       查看下载任务:(下载索引)
       Administration --> Scheduled Tasks 

       方法二(快):
       网上下载Maven仓库索引包(nexus-maven-repository-index.zip) 下载地址:http://download.youkuaiyun.com/detail/pk490525/6520295  
       --> 解压 --> 解压后的文件copy到(sonatype-work --> nexus    
       --> indexer --> central-ctx)下 --> 重启tomcat

      这样,代理就通过映射文件下载到私有服务器了,开发者就可以从私有服务器下载依赖jar包,而不用不断向中央仓库请求下载 


      6>手动上传本地jar包


        选中宿主仓库(3rd part) --> Artifact Upload --> GAV Definition --> GAV Parameters
        --> Select Artifact to Upload --> 选择要上传的jar包 --> 修改组名 -->Add artifact --> Upload Artifact


        这样,本地的jar包就被引进到私有服务器中,并且在组仓库中找 到


       7>修改Maven配置文件从Nexus下载构件


         1)如果对操作系统的所有用户统一配置maven,则只需修改maven\conf\setting.xml文件就可以了,如果只想对用户单独配置maven,只需将conf\setting.xml文件复制到.m2文             件夹下

         2)打开setting.xml文件,可以看到如下代码:
             <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->


        表示如果不设置localRepository,maven会默认将本地仓库创建到.m2/repository文件夹下。设置localRepository如下代     
        码示:<localRepository>D:/movie/repo</localRepository>
 
       
        8>在POM.xml文件中配置Nexus仓库


       
  	<repositories>
		<repository>
			<id>nexus</id>
			<name>my-nexus-repository</name>
			<url>http://127.0.0.1:8080/nexus-


2.9.0/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>nexus</id>
			<name>my-nexus-repository</name>
			<url>http://127.0.0.1:8080/nexus-


2.9.0/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>



          9>在setting.xml文件中配置Nexus仓库:


            1)maven提供了profile来配置仓库信息,如下所示:


   
           		<profile>
			<id>myprofile</id>
			<repositories>
				<repository>
					<id>central</id>
					<url>http://central</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>


			<pluginRepositories>
				<pluginRepository>
					<id>central</id>
					<url>http://central</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>


            
              2)激活profile


               <activeProfiles>
                  <activeProfile>myprofile</activeProfile>
                </activeProfile>



              3)配置镜像


                <mirrors>
                  <mirror>
                  <id>nexus</id>
                  <url>http://127.0.0.1:8080/nexus- 2.9.0/content/group/public/
                  </url>
                  </mirror>
                </mirrors>


           10>将nexus中的自己导入的jar包的坐标复制到pom.xml中


	        <!--excel操作  -->
		<dependency>
			<groupId>cn.zy.jxl</groupId>
			<artifactId>jxl</artifactId>
			<version>2.6.10</version>
		</dependency>



              
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值