搭建Nexus + Maven环境

本文详细介绍在Ubuntu 10.04 LTS下安装Nexus的过程,并通过配置Maven来实现依赖统一管理及快照版本发布。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    本片是前一段时间搭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

 

Xml代码   收藏代码
  1. <settings>  
  2.     <mirrors>  
  3.         <mirror>  
  4.             <!--This sends everything else to /public -->  
  5.             <id>nexus</id>  
  6.             <mirrorOf>*</mirrorOf>  
  7.             <url>http://192.168.0.107:8081/nexus/content/groups/public</url>  
  8.         </mirror>  
  9.     </mirrors>  
  10.     <profiles>  
  11.         <profile>  
  12.             <id>nexus</id>  
  13.             <!--Enable snapshots for the built in central repo to direct -->  
  14.             <!--all requests to nexus via the mirror -->  
  15.             <repositories>  
  16.                 <repository>  
  17.                     <id>central</id>  
  18.                     <url>http://central</url>  
  19.                     <releases><enabled>true</enabled></releases>  
  20.                     <snapshots><enabled>true</enabled></snapshots>  
  21.                 </repository>  
  22.             </repositories>  
  23.             <pluginRepositories>  
  24.                 <pluginRepository>  
  25.                     <id>central</id>  
  26.                     <url>http://central</url>  
  27.                     <releases><enabled>true</enabled></releases>  
  28.                     <snapshots><enabled>true</enabled></snapshots>  
  29.                 </pluginRepository>  
  30.             </pluginRepositories>  
  31.         </profile>  
  32.     </profiles>  
  33.     <activeProfiles>  
  34.         <!--make the profile active all the time -->  
  35.         <activeProfile>nexus</activeProfile>  
  36.     </activeProfiles>  
  37.   
  38.     <!-- 设置发布时的用户名 -->  
  39.     <servers>  
  40.         <server>  
  41.             <id>nexus-releases</id>  
  42.             <username>admin</username>  
  43.             <password>admin123</password>  
  44.         </server>  
  45.         <server>  
  46.             <id>nexus-snapshots</id>  
  47.             <username>admin</username>  
  48.             <password>admin123</password>  
  49.         </server>  
  50.     </servers>  
  51.   
  52. </settings>  
 

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

 

Xml代码   收藏代码
  1.  <properties>  
  2.       <nexus.url>192.168.0.107:8081</nexus.url>  
  3.  </properties>  
  4.    
  5.  <distributionManagement>  
  6.     <repository>  
  7.         <id>nexus-releases</id>  
  8.         <name>Nexus Release Repository</name>  
  9.         <url>http://${nexus.url}/nexus/content/repositories/releases/</url>   
  10.     </repository>  
  11.     <snapshotRepository>  
  12.         <id>nexus-snapshots</id>  
  13.         <name>Nexus Snapshot Repository</name>  
  14.         <url>http://${nexus.url}/nexus/content/repositories/snapshots/</url>   
  15.     </snapshotRepository>  
  16. </distributionManagement>  
 

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

     mvn install

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值