栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

nexus(maven仓库)搭建配置maven本地私有仓库

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

nexus(maven仓库)搭建配置maven本地私有仓库

一 私服的作用,为什么要使用私服?

内网访问,内网团队使用一个服务缓存节省外网宽带。
微服务开发中加速 Maven 项目构建,加快团队合作,提高工作效率
允许上传和下载私有库,并且不被外部访问,安全 稳定。
方便内部项目服务的依赖引用,而不需要其他项目的完整源代码。

1.1 Nexus下载

快速搭建 maven 私服

官网地址:Download Repository OSS  但是速度巨慢;

建议使用百度云盘

小编分享的链接:https://pan.baidu.com/s/1Wgcv_A6YzWuC1NUAhshUcg  提取码:arei

1.2 搭建配置nexus服务

 1.解压下载的 nexus-3.31.1-01-win64.zip 压缩包 解压完之后会有两个文件夹

2.进入到文件夹 nexus-3.31.1-01bin 目录下

3.打开命令窗口 执行 nexus.exe /install nexus 将其安装到Windows服务中

我是因为已经安装过了服务  所以 再次执行  nexus.exe /install nexus 的时候会出现这两行提示

Service is already stopped.
Installed service 'nexus'.

4.使用  nexus.exe /start  或者/stop 进行开启和关闭服务 

服务启动之后默认的端口是8081  访问地址:http://localhost:8081/#browse/welcome

 我这里因为端口冲突 我把端口改成了 8088 下文都将是8088

修改端口可以编辑 nexus-3.31.1-01etcnexus-default.properties 默认的配置文件

 5.登录  点击右上角 sign in 进行登录 默认用户名是 admin

 第一次登录 密码会随机生成 在nexussonatype-worknexus3 目录下有一个password文件中

登陆进去即可修改密码了 

二 使用私服

2.1 私服介绍

hosted,本地存储。像官方仓库一样提供本地私库功能
proxy,提供代理其它仓库的类型
group,组类型,能够组合多个仓库为一个地址提供服务
maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar
maven-releases:私库打包发行版jar
maven-snapshots:私库快照(调试版本)jar
maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。
Hosted有三种方式:Releases、Snapshot、Mixed
Releases: 一般是已经发布的Jar包
Snapshot: 未发布的版本
Mixed:混合的

2.2登录之后左侧会出现一个设置的图标点击进行配置仓库

点击 Create repository创建代理 仓库

 配置阿里云镜像代理

 阿里云镜像仓库服务详见:仓库服务

再创建一个hosted本地仓储用来存放release版本jar

 

 最后双击列表中的maven-public 

设置阿里云镜像优先使用

三 在Maven中使用私服

1.安装配置maven 

官网下载:Maven – Download Apache Maven

 

 2.解压 apache-maven-3.8.5-bin.zip 文件到指定目录 我这里解压到 D:Program Files 路径

配置环境变量

 检查maven配置  

3.设置maven配置在 conf下的settings.xml文件





    
  D://repo

  
    
  

  
  
 
  

  
  
    
    
        maven-releases
        admin
        admin
    
    
        maven-snapshots
        admin
        admin
    
  
  

  
   
     
    
        maven-public
        *
        http://localhost:8088/repository/maven-public/
    
  

  

      
      
        my-profile
        
          1.8  
          1.8  
          1.8
        
        
        
          
            maven-central
            http://localhost:8088/repository/maven-central/
            
                true
            
            
                false
            
          

          
            maven-releases
            http://localhost:8088/repository/maven-releases/
            
                true
            
            
                false
            
          

          
            maven-snapshots
            http://localhost:8088/repository/maven-snapshots/
            
                true
            
            
                true
            
          
      

    
      
        maven-public
        http://localhost:8088/repository/maven-public
      
    
    
    
  
  
  
   my-profile     
  


 4.项目部署和发布的话需要配置: 在pom.xml中添加  distributionManagement 配置


	
		
			maven-releases
			Nexus Releases Repository Pro
			http://localhost:8088/repository/maven-releases/
		

		
			maven-snapshots
			Nexus Snapshots Repository Pro
			http://localhost:8088/repository/maven-snapshots/
		
	

在项目中使用pom.xml进行下载依赖配置的话可以使用:

项目中使用的maven如果已经在settings.xml中配置过后就无需在配置此项

    
		
			repository
			http://localhost:8088/repository/maven-public/
			
				true
			
			
				false
			
		
	
	
		
			central
			http://localhost:8088/repository/maven-central/
			
				true
			
			
				false
			
		
	

 5.可直接在项目中打包部署和发布 

   maven命令介绍:

package命令完成了项目编译、单元测试、打包功能,但并没有把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库和远程maven私服仓库


install命令完成了项目编译、单元测试、打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓3库,但没有布署到远程maven私服仓库


deploy命令完成了项目编译、单元测试、打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库和远程maven私服仓库

如果自己配置的maven一直无法通过idea编译则可以把settings.xml配置文件直接放到idea默认的maven配置文件下进行替换

 

 

6.测试在idea中deploy打包部署你的项目:

如果出现 MojoExecutionException 错误 

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project demo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn -rf :demo
 

请认真检查你的pom.xml 中 distributionManagement 配置是否正确。

7.再次进行打包 全部出现 SUCCESS 说明已经成功部署到了私服仓库

登录到你的nexus私服便可查看部署的jar

全部都在  恭喜你 成功了 Congratulations  

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/932826.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号