http://lichunlong0630.iteye.com/blog/897198
http://192.168.1.107:8081/nexus/index.html#welcome
用Nexus來搭建本地的Maven服務器
下載地址是:http://nexus.sonatype.org/downloads/
我下載的是:nexus-oss-webapp-1.8.0.1-bundle.tar.gz
一、安裝服務器
解壓下載的文件:
# tar xzvf nexus-oss-webapp-1.8.0.1-bundle.tar.gz
解壓后目錄:
nexus-oss-webapp-1.8.0.1 包含了nexus的運行環境和應用程序
sonatype-work 包含了你自己的配置和數據
啟動nexus
進入nexus-oss-webapp-1.8.1目錄
# cd nexus-oss-webapp-1.8.0.1/bin/jsw
根據自己機器選擇版本

我選擇的是 linux-x86-32
# cd linux-x86-32/
linux-x86-32目錄結構 :lib nexus nexus.pid platform.conf wrapper
nexus就是啟動命令
# ./nexus
執行上面的命令,可以得到nexus命令的用法提示:start 命令啟動,stop命令停止。下面啟動nexus:
# ./nexus start

以上表示啟動成功!
通過log文件查看更詳細的信息
# cd ~/nexus-oss-webapp-1.8.0.1/log
# tail -f wrapper.log
在log中可以看到nexus默認監聽的端口是8081。那么我們就可以在瀏覽器中訪問:http://host:8081/nexus
默認用戶名是admin密碼是admin123

二、配置Nexus
由於在新搭建的nexus環境中只是一個空的倉庫,所以第一步就是要和遠程的Maven中心倉庫進行同步。


如果在Reindex之后,並沒有同步到遠程的倉庫,可以檢查每個倉庫的設置。下面是Maven Central的設置:

三、在項目中使用私服
在完成了上面的配置后,就可以將項目中默認的Repository切換為本地的私服了,只需要在pom.xml中增加repositories就可以了:
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.mycom.test</groupId>
- <artifactId>simple</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>simple</name>
- <url>http://maven.apache.org</url>
- <repositories>
- <repository>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- <id>public</id>
- <name>Public Repositories</name>
- <url>http://192.168.1.7:8081/nexus/content/groups/public/</url>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>public</id>
- <name>Public Repositories</name>
- <url>http://192.168.1.7:8081/nexus/content/groups/public//</url>
- </pluginRepository>
- </pluginRepositories>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </project>
將pom.xml保存后,再回過頭來了看去nexus管理界面看,就會發現junit已經被下載到本地的nexus服務器中了。

