maven&nexus_repository 私库搭建与使用

一、nexus仓库安装

1,http://www.sonatype.org/nexus/    下载sso版本,免费
2,tar -zxvf nexus-2.11.1-01-bundle.tar.gz
3,修改端口号    /conf/nexus.properties文件     application-port属性值设置端口号
4,默认端口8081,http://localhost:8081/nexus 访问,默认账号密码 admin,admin123
5,配置服务: nexus自带了service脚本,位于/bin目录下面的nexus文件,将其复制至/etc/init.d目录下,既可以使用service nexus start/restart/stop命令
    chkconfig --add nexus
    chkconfig --level 345 nexus     设置在345运行级别自动启动服务

6,NEXUS仓库介绍:
    6.1    nexus的仓库类型分为以下四种:group: 仓库组,hosted:宿主,proxy:代理,virtual:虚拟
    6.2    首次登陆nexus后可以看到以下一个仓库组和多个仓库:
            Public Repositories:  仓库组
            3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库
            Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库
            Central: 用来代理maven中央仓库中发布版本构件的仓库
            Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库
            Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库
            Releases: 用来部署管理内部的发布版本构件的宿主类型仓库
            Snapshots:用来部署管理内部的快照版本构件的宿主类型仓库
7,基本设置:
    7.1    设置Nexus中的Apache Snapshots、Maven Central、Codehaus Snapshots的下载远程索引:Download Remote Indexes 属性设置为true 默认为false
    7.2    Nexus预定义了“Public Repositories”和“Public Snapshot Repositories”两个仓库组:
        前者默认合并所有预定义的Release仓库,后者默认合并所有预定义的Snapshot仓库。
        点击仓库列表中的“Public Repositories”,然后选择下方的"Configuration" Tab,在配置面板中,将右边“Avaiable Repositories”中的Repository拖拽到左边的“Ordered Group Repository”中

二、linux下maven配置

1,下载 apache-maven-3.2.3-bin.tar.gz
    tar -xvf  apache-maven-3.2.3-bin.tar.gz
2,配置环境变量,编辑/etc/profile文件,添加如下代码
    export MAVEN_HOME=/usr/local/apache-maven-3.0.3
    export PATH=$PATH:$MAVEN_HOME/bin
    配置文件生效source /etc/profile
3,测试maven         mvn-v

三、项目中的maven配置内容  "http://maven.repository.com/为本地私库的域名(自定义)"

1,maven配置文件位于/conf/setting.xml	对于此配置文件的设置,就完成能让本机所有的Maven项目都使用自己的Maven私服
2,修改setting.xml文件
	2.1	设置本地仓库jar保存位置:d:/maven-3.1.0/.m2/repository
	2.2	Nexus 的仓库对于匿名用户是只读权限,为了能够部署构件,还需要在setting.xml 中配置认证信息代码如下:
		  
		   nexus-releases  
		   admin
		   admin123
		
		
		   >nexus-snapshots
		   admin
		   admin123
		 
		 
	2.3	配置镜像地址:
				
			  
				nexus-snapshots  
				public-snapshots  
				http://maven.repository.com/nexus/content/groups/public-snapshots  
			  
			  
				  
				nexus-releases  
				*  
				http://maven.repository.com/nexus/content/groups/public  
			  
			
		这里配置mirrorOf的值为*,代表maven的所有访问请求都会指向到public仓库组。
		
	2.4	配置仓库信息:	
			
			
				public
				
					
						public
						http://maven.repository.com/nexus/content/groups/public
						
							true
						
						
							false
						
					
				
				
					
						public
						http://maven.repository.com/nexus/content/groups/public
						
							true
						
						
							false
						
					
				
			
			
				public-snapshots
				
					
						public-snapshots
						http://maven.repository.com/nexus/content/groups/public-snapshots
						
							false
						
						
							true
						
					
				
				
					
						public-snapshots
						http://maven.repository.com/nexus/content/groups/public-snapshots
						
							false
						
						
							true
						
					
				
			
		
		
	2.4	激活配置
		
			public-snapshots
			public
		
	
	
3,日常开发生成的快照版本构件可以直接部署到Nexus中策略为Snapshot的宿主仓库中,项目正式发布的构件则应该部署到Nexus中策略为Release的宿主仓库中。
	POM.XML配置如下:
	
		
			
				nexus-releases
				Nexus Releases Repository
				http://maven.repository.com/nexus/content/repositories/releases
			
			
				nexus-snapshots
				Nexus Snapshots Repository
				http://maven.repository.com/nexus/content/repositories/snapshots
			
		
	
	
	执行mvn clean deploy  下载部署所需的构件
	
	  

  

四、附:maven配置文件







  
  d:/maven-3.1.0/.m2/repository

  

  
  false
  
  
    
  

  
  
    
  

  
  
    
    
    
     
    
  nexus-releases  
       admin
       admin123
    
  
       nexus-snapshots
       admin
       admin123
     
  

  
  
    
       
          nexus-snapshots  
          public-snapshots  
          http://maven.repository.com/content/groups/public-snapshots  
       
       
            
          nexus-releases  
          *  
          http://maven.repository.com/nexus/content/groups/public  
        
  

  
  
    

    
            public
            
                
                    public
                    http://maven.repository.com/nexus/content/groups/public
                    
                        true
                    
                    
                        false
                    
                
            
            
                
                    public
                    http://maven.repository.com/nexus/content/groups/public
                    
                        true
                    
                    
                        false
                    
                
            
        
  
     
            public-snapshots
            
                
                    public-snapshots
                    http://maven.repository.com/nexus/content/groups/public-snapshots
                    
                        false
                    
                    
                        true
                    
                
            
            
                
                    public-snapshots
                    http://maven.repository.com/nexus/content/groups/public-snapshots
                    
                        false
                    
                    
                        true
                    
                
            
        
    
  
  
  
    public-snapshots
    public
  
  

  

  

你可能感兴趣的:(maven&nexus_repository 私库搭建与使用)