ITeye博客

maven

baggioback · 2012-11-19 10:12 · 技术 · 企业架构 · Markdown

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私服

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

< repositories >

         < repository >

             < id > public < / id >

             < snapshots >

                 < enabled > true < / enabled >

             < / snapshots >

             < name > Public Repositories < / name >

             < url > http : //192.168.0.222:8081/nexus/content/groups/public/</url>

         < / repository >

     < / repositories >

     < pluginrepositories >

         < pluginrepository >

             < id > public < / id >

             < snapshots >

                 < enabled > true < / enabled >

             < / snapshots >

             < name > Public Repositories < / name >

             < url > http : //192.168.0.222:8081/nexus/content/groups/public/</url>

         < / pluginrepository >

     < / pluginrepositories >

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

nexus仓库id与jar包上传

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

< servers >

     < server >

         < id > releases < / id >

         < username > admin < / username >

         < password > easymin < / password >

     < / server >

     < server >

         < id > snapshots < / id >

         < username > admin < / username >

         < password > easymin < / password >

     < / server >

< / servers >

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

1

2

3

4

5

6

7

8

9

10

< distributionmanagement >

     < snapshotrepository >

         < id > snapshots < / id >

         < url > http : //192.168.0.222:8081/nexus/content/repositories/snapshots</url>

     < / snapshotrepository >

     < repository >

         < id > releases < / id >

         < url > http : //192.168.0.222:8081/nexus/content/repositories/releases</url>

     < / repository >

< / distributionmanagement >

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。