本文以Ubuntu Linux为例
一、安装Maven
到官网去下载maven和nexus安装包
maven:http://maven.apache.org/download.cgi
nexus:http://www.sonatype.org/nexus/thank-you-for-downloading/?dl=tgz
本文下载的maven是apache-maven-3.2.5-bin.tar.gz
下载完安装包后,将maven放到硬盘上,cd到maven所在目录,执行命令
tar -zxvf apache-maven-3.2.5-bin.tar.gz
将maven解压缩到硬盘上,打开/etc/profile
vi /etc/profile
按G键找到文件末尾,按小写o进入下一行,输入环境变量
export MAVEN_HOME=/home/zhifang/local/apache-maven-3.2.5 export PATH=$PATH:$MAVEN_HOME/bin
完成后执行
source /etc/profile
然后在控制台执行
mvn -version
出现下面的内容表示maven安装成功
root@zhifang-OptiPlex-3020:/home/zhifang/.m2/repository# mvn -v Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T01:29:23+08:00) Maven home: /home/zhifang/local/apache-maven-3.2.5 Java version: 1.7.0_72, vendor: Oracle Corporation Java home: /home/zhifang/soft/jdk1.7.0_72/jre Default locale: zh_CN, platform encoding: UTF-8 OS name: "linux", version: "3.11.0-15-generic", arch: "amd64", family: "unix"
二、安装Nexus
接下来我们安装nexus,将nexus放到和maven相同的目录,cd切换到该目录,执行下面的命令
tar -zxvf nexus-latest-bundle.tar.gz
nexus解压缩完成后,我们进入nexus目录,去启动nexus
nexus启动是在bin目录下,首先看一下启动/关闭/重启等命令, 输入命令: #cd /usr/local/nexus/bin #./nexus 出现如下选项: [root@test01 bin]# ./nexus Usage: ./nexus { console | start | stop | restart | status | dump } 启动nexus: #./nexus start 关闭nexus: #./nexus stop
启动成功后,打开 http://localhost:8081/nexus,点击右上角login in,输入admin/admin123
登录nexus控制台后,点击左侧列表区的Respositories,右侧会打开一个列表区
依次点击Apache Snapshots,Central,Codehaus Snapshots这三个选项,在打开的窗口里选择Configuration标签,更改Remote Storage Location的值为true,该值默认是false
再右击这三个选项,分别选中Repair Index
三、修改Settings
打开Maven目录下的Settings文件,在profiles选项里增加如下内容
<profile> <id>nexus</id> <repositories> <repository> <id>nexus</id> <name>Nexus</name> <url>http://localhost:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Nexus</name> <url>http://localhost:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile>
在profiles外面增加如下内容,activeProfile的内容要和profile的id保持一致
<activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
在serves里增加如下内容,这个id要和pom.xml的id保持一致
<server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server>
四、eclipse配置
在eclipse里选中window-Preferences-maven-Installactions,将本机安装的maven加载进来,再选中User Settings,在User Settings里加载本机安装的Maven/conf/settings,Local Repository可以不用变更。
配置完成后,在左侧工程区右键新建一个Maven Project工程,Group Id的Artifact Id选中Maven-archetype-quickstart,新建成功。
<distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
<mirror> <id>central</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://192.168.125.77:8081/nexus/content/groups/public/</url> </mirror>