Maven3 安装使用(三)--搭建公司局域网maven服务器

来源:互联网 发布:mac吃鸡 编辑:程序博客网 时间:2024/04/30 05:15
 

Maven3 安装使用(三)--搭建公司局域网maven服务器

分类: 软件安装及环境搭建 9650人阅读 评论(2) 收藏 举报
maven服务器downloadapachewindows浏览器
 

四、搭建公司局域网的Maven服务器

如果在公司里使用Maven,通常应该在本地架设一个Maven资源仓库服务器,在代理远程资源仓库的同时维护本地资源仓库。

第一步: 下载Nexus

从http://nexus.sonatype.org/downloads/下载最新版本的Nexus

如:http://nexus.sonatype.org/downloads/nexus-oss-webapp-1.9.2.4-bundle.zip

前面说已经安装JDK1.6这是nexus所依赖的

解压 到目录 D:\nexus\nexus-oss-webapp-1.9.2.4

Nexus安装目录总有一个兄弟目录,名为“sonatype-work”。这个目录包含有所有资源库和Nexus的配置信息。

第二步:运行服务器

进入到以下目录位置:

D:\nexus\nexus-oss-webapp-1.9.3.4\bin\jsw

在windows系统下,选择自己机器32位还是64位

运行Nexus.bat打开

黑屏下没有报错信息就说明启动成功,默认端口号为0.0.0.0:8081

启动以后,Nexus将处于运行状态并在8081端口上监听为当前主机配置的所有IP地址(0.0.0.0)。要使用Nexus,首先打开一个浏览器,键入URL:http://localhost:8081/nexus。(也可用127.0.0.1或其他配置的IP地址)。这时会打开Nexus的初始欢迎界面。

点击右上方,log in 弹出登录框,默认的用户名:admin ,密码 :admin123

第三步:添加索引

在左侧栏中,选择【Repositories】,右侧会打开用户管理的资源列表。找到上述的三个远程资源库,在下方的属性窗口,将“Download Remote Indexes”设为“true”,并保存修改。

Apache Snapshots

Codehaus Snapshosts

Maven Central

Nexus能够将多个仓库,hosted或者proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。

Nexus预定义了“Public Repositories”仓库组,默认合并所有预定义的Release仓库。

点击列表中的“Public Repositories”,然后选择下方的"Configuration" Tab,在配置面板中,将右边“Avaiable Repositories”中的资源库移动到左边的“Ordered Group Repository”中

如果我们调整Nexus用于局域网内部开发,我们应该配置一个单一的Nexus组,让它包含release和snapshot。要达到这个目的,添加snapshot资源库到我们的公共组(public group),并向Maven的设置文件~/.m2/settings.xml中(Maven 3.0.3 为MAVEN安装目录\conf\settings.xml)添加如下的镜像配置:

<settings>
  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://服务器IP地址:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <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>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

这样配置以后,让团队中所有开发者都指向Nexus中的Public Repository,以后不管我们怎样调整Nexus中的资源库,都不需要团队中的开发者改变他们的本地配置。而管理者对团队应该使用哪个/哪些资源就有了更多地控制。

版权声明:本文为博主原创文章,未经博主允许不得转载。

0 0