windows下集成maven+eclipse开发环境二:集成maven到eclipse,并使用nexus作为maven仓库

上一章中,我们已经成功安装了nexus,现在我们将在eclipse中集成maven插件,并将nexus配置成maven的仓库。

 

1、安装eclipse的svn插件subeclipse,打开你的eclipse(笔者使用的是eclipse 3.6),依次打开help->Software Updates->Find and instill;如下图:

 

image

 

在弹出的窗口中选择第二个单选框,然后下一步:

image

 

点击右面的New Remote site…按钮,新建一个远程插件更新地址,在弹出的对话框中填写如下内容:

Name:subeclipse(名字可以随便填)

URL:http://subclipse.tigris.org/update_1.6.x

 

image

 

在短暂的读条过程之后会依次出现若干个对话框,有询问的一律统一,然后Next或者Finish到底就是了。之后会开始插件的安装,eclipse会从远程下载插件安装,安装完毕后,会提示重启eclipse。如果重启后能在视图菜单中找到SVN资源库研究就说明安装成功了,如图:

image

 

maven插件的安装稍微要不同一点,首页help->install new software…在弹出的对话框中点击add按钮,然后再在弹出的对话框中填入下面的内容:

Name:m2e

URL:http://m2eclipse.sonatype.org/sites/m2e

 

image

 

在点击ok后,eclipse会从远程服务器读取相关信息,直到出现:

 

image

 

勾选这条记录,然后一路Next到Finish。然后eclipse会从远程服务器下载m2e插件(下载速度敢不敢再慢点..擦!),后面的过程与安装svn插件时基本相同了,在这里就不阐述了。

重庆之后如果出现如下警告,请参照该地址的解决办法:http://www.sunchis.com/html/hsware/software/2011/1102/371.html

image

 

好了,如果在新建菜单中出现了maven的相关项就说明安装maven成功了!如下图:

 

image

 

然后我们开始配置maven,将nexus配置为maven的仓库。

 

安装完m2e后,会在用户文件夹下面的新建一个中央仓库文件夹,而因为是直接安装的eclipse的m2e插件,所以需要手动新建一个setting.xml文件。

进入目录:C:\Users\用户名\.m2

然后新建一个settings.xml文件,内容如下

 

settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
    <mirror>
      <!--This is used to direct the public snapshots repo in the 
          profile below over to a different nexus group -->
      <id>nexus-public-snapshots</id>
      <mirrorOf>public-snapshots</mirrorOf>
      <url>http://127.0.0.1:8081/nexus/content/groups/public-snapshots</url>
    </mirror>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://127.0.0.1:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>development</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
    <profile>
      <!--this profile will allow snapshots to be searched when activated-->
      <id>public-snapshots</id>
      <repositories>
        <repository>
          <id>public-snapshots</id>
          <url>http://public-snapshots</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>public-snapshots</id>
          <url>http://public-snapshots</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>development</activeProfile>
  </activeProfiles>
</settings>

 

根据Maven权威指南描述:

 


在你将Nexus 配置成所有仓库的镜像之后,Maven 现在会从本地的 Nexus 安装
查阅,而非去外面查阅中央Maven 仓库。如果对Nexus 有一个构件请求,本地
的Nexus 安装会提供这个构件。如果 Nexus 没有这个构件,Nexus 会从远程仓库
获取这个构件,然后添加至远程仓库的本地镜像。
要测试Nexus 如何工作的,从你的本地Maven 仓库中删除一个目录,然后运行
Maven 构建。如果你删除了~/.m2/repository/org,你会删除一大堆的依赖(包
括Maven 插件)。下次你运行Maven 的时候,你应该看到如下的信息: 
$ mvn clean install 
...
Downloading: http://localhost:8081/nexus/content/groups/public/ ...
3K downloaded
这个输出应该能让你相信Maven 正和你本地的Nexus 通讯,而非向外面的中央
Maven 仓库获取构件。在你基于本地的 Nexus 运行过一些构建之后,你就可以浏
览缓存在你本地Nexus 中的内容。登陆Nexus 然后点击导航菜单的左边的构件
搜索。在搜索框中输入"maven" ,你应该能看到一些像下面的内容。


至此为止,本章的内容已经全部完成。下一章将介绍如何在该环境下创建SSH环境。

posted @ 2012-05-18 16:52  Fat--  阅读(1881)  评论(0编辑  收藏  举报