代码改变世界

Maven实战(Maven+Nexus建立私服【Linux系统】)

2013-04-03 17:11  飘扬的红领巾  阅读(8696)  评论(0编辑  收藏  举报

准备工作

下载及配置Maven3:http://www.cnblogs.com/leefreeman/archive/2013/03/05/2944519.html

下载Nexus:http://nexus.sonatype.org/downloads/

安装配置Nexus

Nexus提供了两种安装方式,一种是内嵌Jetty的bundle,只要你有JRE就能直接运行。第二种方式是WAR,你只须简单的将其发布到web容器中即可使用。

image

建议下载上面这个,下载完成之后,解压到linux的相应位置:

image

上图中的 nexus-2.3.1-01和sonatype-work目录就是解压tar包后的两个目录,nexus-2.3.1-01中是nexus的核心文件,sonatype-work,会将下载来的开发包放置在其中。

cd /data/program/nexus-2.3.1-01/bin/jsw
ll

image

可以看到很多操作系统的版本目录,选择你的linux系统版本进去,如果不知道可以:

uname –a

image

然后进入:

image

启动nexus

./nexus start

image

nexus启动成功,访问:http://192.168.6.204:8081/nexus/

image

点击右上角的“log on”进行登录,默认用户名和密码:admin / admin123

可以看到左边菜单:

image

点击“Repositories”

image

关于hosted、proxy、group的概念这里就不讲了,大都介绍nexus的都有介绍,这里主要讲需要做的配置?

点击Central,并切换到Configuration选项卡。

image

将Download Remote Indexes项设为True!这将打开nexus的下载远程索引的功能,便于使用nexus的搜索功能。

配置Maven使用Nexus私服

修改Maven的settings.xml 文件。

在<settings></settings>之间添加:

<profiles>
        <profile>
            <id>dev</id>
            <repositories>
                <repository>
                    <id>local-nexus</id>
                    <url>http://192.168.6.204:8081/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
    </profiles>

    <!-- activeProfiles | List of profiles that are active for all builds. | -->
    <activeProfiles>
        <activeProfile>dev</activeProfile>
    </activeProfiles>

注意原settings.xml 文件中,已经存在profiles、activeProfiles的节点。

如果你的eclipse,安装了m2eclipse插件,则设置:

image

image

这样当项目需要开发包时,就会在本地仓库查找,如果查找不到就会到私服上查找,如果还查找不找就会去中央仓库去查找。下次等另一人需要同样的开发包时,就会从私服中查找,效果远比他重新从中央仓库下载快多了。

未命名