`
witcheryne
  • 浏览: 1094485 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

搭建Nexus + Maven环境

阅读更多

 

     本片是前一段时间搭Mvn + Neuxs环境, 在EverNote中做的笔记,今天把它腾到这里重新排版

前言

     上周末终于把netmanage30项目迁移到了mvn环境下,其中各种折腾.现在终于熟悉了maven的使用方式.

     按照best parctice需要使用nexus来做依赖管理服务器.在个人开发的方式下优势估计不是很明显,不过在团队开发中好处不言而喻.

     说了这么多nexus到底有什么好处:

          1. 统一管理依赖的jar包,作为一mvn的代理,所有链接到nexus上的用户公用一套nexus中的jar包.这样团队中之需要下载一次依赖

          2. 团队中开发的bundle可以发布到nexus中进行共享.

          3. mvn + nexus提供一种snapshot(快照)的版本发布方式.关于snapshot版本控制,下面这篇文章介绍的很详细:

               http://juvenshun.iteye.com/blog/376422

 

在Ubuntu 10.04LTS 下安装Nexus

 

     关于Nexus安装在哪里的问题,我毫不犹豫的选择Virtual Box虚拟机.好处就是研发环境如何变化,管理平台的环境始终保持不变.

     ok~ 说了这么多废话,下面开始nexus安装, 在安装时我直接使用的root用户,如果选择其他用户需要使用sudo来提升权限, 如果不知道如何使用root用户的朋友可以使用如下指令:

 

     #修改root密码,可以理解成激活root用户

     passwd root          

 

     提示输入密码, 输入两遍即可.

     注销当前用户,用root用户登录即可

 

1. 寻找最新版本的Nexus和文档

 

     官方网站: http://nexus.sonatype.org/

     官方文档: http://www.sonatype.com/books/nexus-book/reference/

 

2. 下载合适的Nexus

 

     下载地址: http://nexus.sonatype.org/downloads/

     Nexus分代jetty的独立版和war包形式的部署版,如果已经有随机启动的servlert contaner可以采用war形式,本次我打算采用独立版

     独立版选择 *.tar.gz/*.zip 压缩包即可:

          wget http://nexus.sonatype.org/downloads/nexus-oss-webapp-1.9.2-bundle.tar.gz

 

3. 安装Nexus
     1). 解压缩

               tar -zvxf nexus-oos-webapp-1.9.2-bundle.tar.gz

 

     2). 将文件移动到对应路径,并将文件名重命名为nexus-1.9.2

               mv ./nexus-oos-webapp-1.9.2-bundle.tar.gz /usr/local/nexus-1.9.2

 

     3). 首次运行nexus:(注意: 在此之前需要确保配置好了java环境)

               /usr/local/nexus-1.9.2/bin/jsw/linux-x86-32/nexus start

               #监视一下日志

               tail -f /usr/local/nexus-1.9.2/logs/wrapper.log

 

     4). 访问如下地址访问Nexus:

               http://localhost:8081/nexus

 


 

     到此,如果不想做额外,nexus已可以使用.下面需要配置"环境变量"和"系统服务",好处就是可以方便使用.

 

4. 添加环境变量

 

     1).编辑profile文件

          gedit ~/.profile

 

     2).加入如下内容:

               export NEXUS_HOME=/usr/local/nexus-1.9.2

               export PATH=$NEXUS_HOME/bin/jsw/linux-x86-32/:$PATH

     3). 重新登录之后可以使其生效

          试试 nexus console

 

5. 增加启动服务:

 

     1). 将$NEXUS_HOME/bin/jsw/bin/linux-x86-32/nexus复制到/etc/init.d下

               cp $NEXUS_HOME/bin/jsw/bin/linux-x86-32/nexus /etc/init.d

 

     2). 编辑/etc/init.d/nexus

               gedit /etc/init.d/nexus

               修改如下内容:

               # Application

               APP_NAME="nexus"

               APP_LONG_NAME="Sonatype Nexus"

               NEXUS_HOME=/usr/local/nexus-1.9.2

               PLATFORM=linux-x86-32

 

               # Wrapper

               WRAPPER_CMD=$NEXUS_HOME/bin/jsw/$PLATFORM/wrapper

               WRAPPER_CONF=$NEXUS_HOME/bin/jsw/conf/wrapper.conf

 

               # Location of the pid file.

               PIDDIR="/var/run"

 

     3). 添加成服务,并执行

               cd /etc/init.d

               update-rc.d nexus defaults

 

               #执行

               service nexus start

               #Starting Sonatype Nexus...

               tail -f /usr/local/nexus/logs/wrapper.log

 

让Maven链接上Nexus

 

1. 修改maven设置

     一般我们修改用户设置, ~/.m2/settings.xml

 

<settings>
    <mirrors>
        <mirror>
            <!--This sends everything else to /public -->
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.0.107: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>

    <!-- 设置发布时的用户名 -->
    <servers>
        <server>
            <id>nexus-releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>

</settings>
 

2. 在项目pom.xml设置发布目录:

 

     <properties>
          <nexus.url>192.168.0.107:8081</nexus.url>
     </properties>
     
     <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://${nexus.url}/nexus/content/repositories/releases/</url> 
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://${nexus.url}/nexus/content/repositories/snapshots/</url> 
        </snapshotRepository>
    </distributionManagement>
 

3. 估计已经迫不及待的尝试了

     mvn install

 

     Maven一般会先从本地读取jar文件,如果找不到再从远程服务器上读取, 如果之前在没有nexus下使用过mvn,可以先将本地仓库清空,之后在运行mvn install

 

 

  • 大小: 40.9 KB
分享到:
评论
1 楼 镜花水月EYE 2013-05-29  
谢谢分享。

相关推荐

Global site tag (gtag.js) - Google Analytics