maven与nexus简单安装配置

 摘取:

一、Installing Maven
  ----------------

  1) Unpack the archive where you would like to store the binaries, eg:

    Unix-based Operating Systems (Linux, Solaris and Mac OS X)
      tar zxvf apache-maven-3.0.x.tar.gz
    Windows 2000/XP
      unzip apache-maven-3.0.x.zip

  2) A directory called "apache-maven-3.0.x" will be created.

  3) Add the bin directory to your PATH, eg:

    Unix-based Operating Systems (Linux, Solaris and Mac OS X)
      export PATH=/usr/local/apache-maven-3.0.x/bin:$PATH
    Windows 2000/XP
      set PATH="c:\program files\apache-maven-3.0.x\bin";%PATH%

  4) Make sure JAVA_HOME is set to the location of your JDK

  5) Run "mvn --version" to verify that it is correctly installed.

 

二、nexus安装及配置

本文参考:http://aijezdm915.iteye.com/blog/1335025

                   http://hi.baidu.com/gavin_mars/item/0055d415a8ed56098fbde46d

1.建议下载nexus-oss-webapp-1.8.0.1

(对于初学者,建议下载此版本,简单实用,不易出错)

地址:http://www.sonatype.org/nexus/archived

2.安装nexus

解压后,在nexus-oss-webapp-1.8.0.1  ------->bin------>jsw\windows-x86-32下点击nexus.bat即可

(双击Installnexus.bat也可将应用注册为Windows服务。)

3.验证是否安装成功

打开浏览器,输入http://127.0.0.1:8081/nexus正常显示,并输入admin/admin123登录。

4.添加代理Maven中央仓库

      a.类型介绍:

      hosted:本地仓库,通常部署自己的构件到这一类型的仓库。
      proxy   :代理仓库,被用来代理远程的公共仓库,如maven中央仓库。
      group  :仓库组,用来合并多个hosted/proxy仓库,通常配置maven依赖仓库组。

      virtual  :虚拟库

       b.建立Maven中央仓库的代理Proxy

        点击Repositories,点击add添加,选择代理仓库,定义id,name后,需要填写Remote Storage Location为:http://repo1.maven.org/maven2/

        Download Remote Indexes设置为false;然后点保存。

5.本地maven仓库管理

        Nexus已经预定义了3个本地仓库,分别为Releases,Snapshots,和3rd Party。这三个仓库分别为Releases用于部署我们自己的release构件,

Snapshots用于部署我们自己的snapshot构件,而3rd Party用于部署第三方构件,有些构件如Oracle的JDBC驱动,就需要将其部署到自己的仓库中。

6.管理Maven仓库组

Nexus中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,我只管根据groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容 。

7.搜索构件

Nexus基于nexus-indexer提供构件搜索功能,想要对仓库进行搜索,无论是hosted,proxy,或者group,都必须确认索引文件存在,这一点对于代理仓库尤其重要。

最开始时间比较慢,若Nexus拥有了本地或者远程仓库的索引文件,就可以享受Nexus的构件搜索功能了。

 

三、配置maven使用nexus

默认情况下,maven是使用中央仓库的,所以会造成严重的网络带宽和烦躁的心里负担,作者就是在这样的情况下,才决定学习使用nexus的,并参考相关文档,

写成粗略小记,供一起学习。

1.将maven与nexus进行关联

两种方式:一种是直接将仓库配置在工程的pom.xml中,不建议采用。

                    另一种是配置在$user_home/.m2/settings.xml中,例如C:\Documents and Settings\user\.m2\。

<profiles>
 <profile>
      <id>development</id>
      <repositories>
        <repository>
          <id>proxymavenrepository</id>
          <name>proxy Maven Repository</name>
          <url>http://127.0.0.1:8081/nexus/content/repositories/proxymavenrepository/</url>
          <layout>default</layout>
    <releases>
   <enabled>true</enabled>
    </releases>
    <snapshots>
   <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>development</activeProfile>
  </activeProfiles>

2.部署构件到nexus

(1)nexus界面上传

步骤如下:

点击左边导航栏的"Repository",在右边的仓库列表中选择一个仓库,如“3rd Party”,然后会看到页面下方有四个tab,选择最后一个“Upload”,你会看到构件上传界面。选择你要上传的构件,并指定POM,(或者手工编写GAV等信息),最后点击Upload,该构件就直接被部署到了Nexus的"3rd Party"仓库中.

(2)通过maven 部署

即修改pom.xml配置和settings.xml通过Maven自动化部署构件

pom.xml文件:

<distributionManagement>  
<repository>  
<id>nexus-releases</id>  
<name>Nexus Release Repository</name>  
<url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>  
</repository>  
<snapshotRepository>  
<id>nexus-snapshots</id>  
<name>Nexus Snapshot Repository</name>  
<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>  
</snapshotRepository>  
</distributionManagement>  

 

setting.xml文件:

<servers>  
 <server>  
  <id>nexus-releases</id>  
  <username>admin</username>  
  <password>admin123</password>  
 </server>  
 <server>  
  <id>nexus-snapshots</id>  
  <username>admin</username>  
  <password>admin123</password>  
 </server>     
</servers>

 

 

       

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值