Maven2 学习笔记[4]-用Artifactory搭建maven私服

Maven2 学习笔记[4]-用Artifactory搭建maven私服

搭建repository私服的用处有很多。
除了如何如何管理好jar包外,还有就是当 maven2 无法自动获取某个jar包时,(例如 oracle的jdbc jar包)
我们需要手动下载此jar包,将其上传至我们得私服,填写groupId,artifactId,version等信息。
然后再在pom.xml里进行依赖配置。

我搭建私服的工具是artifactory-2.2.3。
首先到网上下载artifactory-2.2.3,google一下,什么都有了。
下载好后,将其解压到任意目录。
由于artifactory自带了Jetty Web服务器,所以,只要双击\bin\artifactory.bat 即可运行。(太方便了)
待服务器启动好后,用 http://localhost:8081/artifactory/ 开发页面。
默认的用户名密码是:admin/password.
画面如下:


输入用户名:admin 密码:password 登录。

进入画面后,点击Deploy,选择要上传的jar包。


选中jar包后,点击 Upload,会弹出 如下图画面:


这里的GroupId、ArtifactId、Version便是要在pom.xml里添加依赖时指定的元素。
同时,可以点击POM Editor 来对它的 pom.xml进行编辑。如下代码:

<? xml version="1.0" encoding="UTF-8" ?>
< project  xsi:schemaLocation ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"  xmlns ="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" >
  
< modelVersion > 4.0.0 </ modelVersion >
  
< groupId > poi </ groupId >
  
< artifactId > poi </ artifactId >
  
< version > 3.6 </ version >
  
< description > Artifactory auto generated POM </ description >
</ project >


这还不算完!!这只是建立了repository私服,但是怎样告诉maven在compile、package时去本地私服寻找依赖包呢?

有两种方式来配置,一是在settings.xml里指定,二是在项目的pom.xml中指定。

我是在settings.xml中进行指定,在settings.xml文件中,加入Profile节点。
(关于此节点的说明,请参见:http://www.blogjava.net/jnbzwm/archive/2010/09/03/330862.html)


< profiles >
    
< profile >
      
< id > localrepo </ id >
      
< activation >
        
< jdk > 1.6 </ jdk >
      
</ activation >
      
< repositories >
        
< repository >
          
< id > central </ id >
          
< name > artifactory at local </ name >
          
< url > http://localhost:8081/artifactory/repo </ url >
          
< layout > default </ layout >
          
< snapshots >    
            
< enabled > false </ enabled >    
         
</ snapshots >
        
</ repository >
        
< repository >    
         
< id > snapshots </ id >    
          
< url > http://localhost:8081/artifactory/repo </ url >    
           
< releases >    
            
< enabled > false </ enabled >    
           
</ releases >    
        
</ repository >
      
</ repositories >
      
< pluginRepositories >
        
< pluginRepository >
            
< id > artifactory </ id >
            
< name > artifactory plugins at local  </ name >
            
< url > http://localhost:8081/artifactory/plugins-releases </ url >
            
< snapshots >
                
< enabled > false </ enabled >
            
</ snapshots >
        
</ pluginRepository >
    
</ pluginRepositories >
</ profiles >

在前一个学习笔记中有提到,配置profile后,需要进行激活,所以再在settings.xml中,加入activeProfiles节点的配置。

   < activeProfiles >
    
< activeProfile > localrepo </ activeProfile >
  
</ activeProfiles >

这里指定的localrepo 就是我们配置的profile的Id。

到此,配置结束。


本文为原创,欢迎转载,转载请注明出处BlogJava。

你可能感兴趣的:(Maven2 学习笔记[4]-用Artifactory搭建maven私服)