---
title: "maven"
author: "baggioback"
date: "2012-11-19T10:12:26Z"
tags: []
categories: ["企业架构"]
slug: "maven"
draft: false
lastmod: "2012-11-19T10:12:26Z"
id: 1729315
url: "https://baggioback.iteye.com/blog/1729315"
---

Maven是一个相当不错的项目管理工具，我们在开发项目的时候经常会使用一些自己开发的jar包等，所以有必要搭建自己的私服，用于快速部署自己的jar包，来快速集成项目。  
首先我们先下载Nexus,下载地址为,我下载的是zip版本的,linux下可以下载tgz版本的。下载完成后我们得到的是一个nexus-2.0.6-bundle.zip  
然后解压nexus-2.0.6-bundle.zip，我们将会的到一个目录名为nexus-2.0.6-bundle,里面有nexus-2.0.6和sonatype-work两个目录。  
接下来就先选择一个你要安装的地方，把nexus-2.0.6-bundle移动到你要安装的位置。我存放的地址为:E:\\nexus-2.0.6- bundle。接下来我们进入cmd,然后cd到E:\\nexus-2.0.6-bundle\\nexus-2.0.6\\bin目录里面,运行

1

nexus install

等到提示服务安装启动成功后，我们打开浏览器访问:,然后可以点击右上角的Log in输入用户名 admin 密码 admin123（默认） 登录系统，进入系统界面如下:

[![Maven的Nexus私服](http://www.javafans.org/wp-content/uploads/2012/07/maven_nexus-300x145.png "Maven的Nexus私服")](http://www.javafans.org/wp-content/uploads/2012/07/maven_nexus.png)

Maven的Nexus私服

进入主界面后要做的事情就是点击Change Password修改默认的密码，然后点击Repositories来配置我们的仓库，具体有哪些仓库大家可以百度找找，我就不详细描述了，这样我们的私服就安装OK了。

现在就是我们怎么来使用我们的私服的问题了，首先我们在项目的POM.xml中增加仓库地址，具体代码如下:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

&lt; repositories &gt;

         &lt; repository &gt;

             &lt; id &gt; public &lt; / id &gt;

             &lt; snapshots &gt;

                 &lt; enabled &gt; true &lt; / enabled &gt;

             &lt; / snapshots &gt;

             &lt; name &gt; Public Repositories &lt; / name &gt;

             &lt; url &gt; http : //192.168.0.222:8081/nexus/content/groups/public/&lt;/url&gt;

         &lt; / repository &gt;

     &lt; / repositories &gt;

     &lt; pluginrepositories &gt;

         &lt; pluginrepository &gt;

             &lt; id &gt; public &lt; / id &gt;

             &lt; snapshots &gt;

                 &lt; enabled &gt; true &lt; / enabled &gt;

             &lt; / snapshots &gt;

             &lt; name &gt; Public Repositories &lt; / name &gt;

             &lt; url &gt; http : //192.168.0.222:8081/nexus/content/groups/public/&lt;/url&gt;

         &lt; / pluginrepository &gt;

     &lt; / pluginrepositories &gt;

这样我们就可以下载到jar包了，那么我们怎么部署自己的jar包到私服里面呢？目前我有两个方法  
方法一：  
进入管理界面  
选择Repositories -&gt; 选择Releases或者Snapshots -&gt;Artifact Upload来上传自己的Jar包。

[![nexus仓库id与jar包上传](http://www.javafans.org/wp-content/uploads/2012/07/nexus-repository-id-upload-300x103.png "nexus-repository-id-upload")](http://www.javafans.org/wp-content/uploads/2012/07/nexus-repository-id-upload.png)

nexus仓库id与jar包上传

方法二：  
使用maven的Deploy来部署我们的jar包到远程仓库，首先我们要配置部署所需要的帐号和密码，这个需要在maven的setting.xml中的servers节点配置，我的配置如下:  
注意这里的id要与nexus里面的Repository ID相同,上面的图片有特别标注。

1

2

3

4

5

6

7

8

9

10

11

12

&lt; servers &gt;

     &lt; server &gt;

         &lt; id &gt; releases &lt; / id &gt;

         &lt; username &gt; admin &lt; / username &gt;

         &lt; password &gt; easymin &lt; / password &gt;

     &lt; / server &gt;

     &lt; server &gt;

         &lt; id &gt; snapshots &lt; / id &gt;

         &lt; username &gt; admin &lt; / username &gt;

         &lt; password &gt; easymin &lt; / password &gt;

     &lt; / server &gt;

&lt; / servers &gt;

接下来还需要在pom.xml文件中加入部署管理，代码如下：  
注意这里的id要与nexus里面的Repository ID相同,上面的图片有特别标注。

1

2

3

4

5

6

7

8

9

10

&lt; distributionmanagement &gt;

     &lt; snapshotrepository &gt;

         &lt; id &gt; snapshots &lt; / id &gt;

         &lt; url &gt; http : //192.168.0.222:8081/nexus/content/repositories/snapshots&lt;/url&gt;

     &lt; / snapshotrepository &gt;

     &lt; repository &gt;

         &lt; id &gt; releases &lt; / id &gt;

         &lt; url &gt; http : //192.168.0.222:8081/nexus/content/repositories/releases&lt;/url&gt;

     &lt; / repository &gt;

&lt; / distributionmanagement &gt;

然后我们就可以使用 mvn deploy命令进行部署了,其他项目只要可以访问http://192.168.0.222:8081/nexus/content/groups/public/的都可以下载到刚部署上去的新包了。