maven私服的使用:包括搭建和使用

记下来,方便自己以后忘了回来查阅

下载nexus

Nexus Maven仓库管理器,通过nexus可以搭建maven仓库,同时nexus还提供强大的仓库管理功能,构件搜索功能等。

下载Nexus 下载地址:http://www.sonatype.org/nexus/archived/

下载:nexus-2.12.0-01-bundle.zip

安装nexus

解压nexus-2.12.0-01-bundle.zip,本教程将它解压在F盘,进入bin目录:

maven私服的使用:包括搭建和使用_第1张图片

cmd进入bin目录,执行nexus.bat install


安装成功在服务中查看有nexus服务:

卸载nexus

cmd进入nexusbin目录,执行:nexus.bat uninstall


查看window服务列表nexus已被删除。

启动nexus

方法1

cmd进入bin目录,执行nexus.bat start

方法2

直接启动nexus服务

maven私服的使用:包括搭建和使用_第2张图片

查看nexus的配置文件conf/nexus.properties

maven私服的使用:包括搭建和使用_第3张图片

# Jetty section

application-port=8081   # nexus的访问端口配置

application-host=0.0.0.0  # nexus主机监听配置(不用修改)

nexus-webapp=${bundleBasedir}/nexus  # nexus工程目录

nexus-webapp-context-path=/nexus  # nexusweb访问路径

# Nexus section

nexus-work=${bundleBasedir}/../sonatype-work/nexus   # nexus仓库目录

runtime=${bundleBasedir}/nexus/WEB-INF  # nexus运行程序目录

访问:

http://localhost:8081/nexus/


使用Nexus 内置账户admin/admin123登陆:

点击右上角的Log in,输入账号和密码 登陆

将项目发布到私服

配置

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

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


      releases
      admin
      admin123
    
	
      snapshots
      admin
      admin123
    

releases 连接发布版本项目仓库

snapshots 连接测试版本项目仓库

第二步: 配置项目pom.xml

配置私服仓库的地址,本公司的自己的jar包会上传到私服的宿主仓库,根据工程的版本号决定上传到哪个宿主仓库,如果版本为release则上传到私服的release仓库,如果版本为snapshot则上传到私服的snapshot仓库


  	
  		releases
	http://localhost:8081/nexus/content/repositories/releases/
  	 
  	
  		snapshots
	http://localhost:8081/nexus/content/repositories/snapshots/
  	 
  

注意:pom.xml这里 settings.xml 配置 对应!

测试

将项目dao工程打成jar包发布到私服:

1、首先启动nexus

2、对dao工程执行deploy命令

根据本项目pom.xmlversion定义决定发布到哪个仓库,如果version定义为snapshot执行deploy后查看nexussnapshot仓库如果version定义为release则项目将发布到nexus的release仓库,本项目将发布到snapshot仓库:

从私服下载jar

 setting.xml中配置仓库

在客户端的setting.xml中配置私服的仓库,由于setting.xml中没有repositories的配置标签需要使用profile定义仓库。

   
	
   dev   
       
        
		
        nexus   
		
        http://localhost:8081/nexus/content/groups/public/   
		
           
          true   
           
		
           
          true   
           
         
      
	   
    	
          
        	
            public  
            Public Repositories  
            http://localhost:8081/nexus/content/groups/public/  
          
      
    

使用profile定义仓库需要激活才可生效。

 
    dev
  

配置成功后通过eclipse查看有效pom,有效pommaven软件最终使用的pom内容,程序员不直接编辑有效pom,打开有效pom

有效pom内容如下:

下边的pom内容中有两个仓库地址,maven会先从前边的仓库的找,如果找不到jar包再从下边的找,从而就实现了从私服下载jar包。


    
      
        true
      
      
        true
      
      public
      Public Repositories
      http://localhost:8081/nexus/content/groups/public/
    
    
      
        false
      
 central
      Central Repository
      https://repo.maven.apache.org/maven2
    
  
  
    
      public
      Public Repositories
      http://localhost:8081/nexus/content/groups/public/
    
    
      
        never
      
      
        false
      
      central
      Central Repository
      https://repo.maven.apache.org/maven2
    
  

暂时就这些吧  以后记得了在向上传,

你可能感兴趣的:(Java)