環境搭建
1、linux安裝maven
tar zxvf apache-maven-3.0.5-bin.tar.gz
mv
apache-maven-3.0.5 /usr/local/
apache-maven-3.0.5
vi /etc/profile
增加:
export MAVEN_HOME=/usr/local/apache-maven-3.0.5
export PATH=$PATH:$MAVEN_HOME/bin
export PATH=$PATH:$MAVEN_HOME/bin
source /etc/profile
mvn -v
2、linux安裝nexus
需要的安裝包:nexus-2.11.4-01-bundle.tar(csdn下載地址:http://download.csdn.net/detail/carboncomputer/9595216)
需要jdk版本1.7以上
tar zxvf
nexus-2.11.4-01-bundle.tar
端口配置文件,可修改端口:/nexus-2.11.4-01/conf/nexus.properties
cd nexus-2.11.4-01/bin
./nexus start
如果啟動成功,就會顯示如下:

如果在啟動過程中說要求root權限的。可以百度解決,或者用
sudo sh nexus start啟動。
用默認的賬號密碼登錄:admin/admin123
環境就部署好了,現在是使用maven倉庫。
注意:嚴重不提倡使用nexus3.0以上的版本,一開始用這個,安裝時很多問題需要解決,此外,新的界面很難使用。官網上也是推薦使用maven時采用nexus2.X版本。
maven倉庫使用及版本發布管理
點擊倉庫列表

主要是兩個類型:
snapshots:開發過程中的版本倉庫
release:正式發布的版本倉庫
public是maven主庫
nexus默認新建了一個庫:3rd party,專門存放第三方的jar,這個所搜搜幾篇文章看看就有說明了。這里對於這個不一一說了,主要是介紹如何使用nexus來管理版本和本地開發過程。
上傳第三方的jar如下:

snapshots、release全部開發允許部署的權限,如下


本地是windows下的myeclipse10進行開發的,myeclipse10自帶maven插件,直接使用,不需要加載這個插件,其他的比如eclipse需要自行處理。
myeclipse配置setting.xml

現在來看看setting.xml文件

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:/maven/maven_jars</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>releases</id>
<username>deployment</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>deployment</username>
<password>admin123</password>
</server>
<server>
<id>public</id>
<username>deployment</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>nexus</mirrorOf>
<name>nexus Repositories</name>
<url>http://xxx.xx.xx.xx:8081/nexus/content/repositories/thirdparty/</url>
</mirror>
</mirrors>
<profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
</settings>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:/maven/maven_jars</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>releases</id>
<username>deployment</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>deployment</username>
<password>admin123</password>
</server>
<server>
<id>public</id>
<username>deployment</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>nexus</mirrorOf>
<name>nexus Repositories</name>
<url>http://xxx.xx.xx.xx:8081/nexus/content/repositories/thirdparty/</url>
</mirror>
</mirrors>
<profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
</settings>
建立maven工程

pom.xml的內容設置如下:


<
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
>
News_Recommend
</
groupId
>
<
artifactId
>
News_Recommend
</
artifactId
>
<
version
>
0.0.5-SNAPSHOT
</
version
>
<
packaging
>
jar
</
packaging
>
<!-- 設定主倉庫 -->
<
repositories
>
<!-- nexus私服 -->
<
repository
>
<
id
>
public
</
id
>
<
url
>
http://xxxx
:8081/nexus/content/groups/public/
</
url
>
<
releases
>
<
enabled
>
true
</
enabled
>
</
releases
>
<
snapshots
>
<
enabled
>
true
</
enabled
>
</
snapshots
>
</
repository
>
</
repositories
>
<!-- 自動打包 -->
<
distributionManagement
>
<
repository
>
<
id
>
releases
</
id
>
<
url
>
http://xxxx:8081/nexus/content/repositories/releases
</
url
>
</
repository
>
<
snapshotRepository
>
<
id
>
snapshots
</
id
>
<
url
>
http://xxxx
:8081/nexus/content/repositories/snapshots
</
url
>
</
snapshotRepository
>
</
distributionManagement
>
<
dependencies
>
<
dependency
>
<
groupId
>
junit
</
groupId
>
<
artifactId
>
junit
</
artifactId
>
<
version
>
3.8.1
</
version
>
<
scope
>
test
</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>
com.oracle
</
groupId
>
<
artifactId
>
ojdbc
</
artifactId
>
<
version
>
10.1.0.2.0
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
com
</
groupId
>
<
artifactId
>
testjar
</
artifactId
>
<
version
>
1.0.0
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
News_Recommend
</
groupId
>
<
artifactId
>
News_Recommend
</
artifactId
>
<
version
>
0.0.1
</
version
>
</
dependency
>
</
dependencies
>
<
build
>
<
plugins
>
<
plugin
>
<
groupId
>
org.apache.maven.plugins
</
groupId
>
<
artifactId
>
maven-compiler- plugin
</
artifactId
>
<
configuration
>
<
source
>
${jdk.version}
</
source
>
<
target
>
${jdk.version}
</
target
>
</
configuration
>
</
plugin
>
<
plugin
>
<
groupId
>
org.apache.maven.plugins
</
groupId
>
<
artifactId
>
maven-war-plugin
</
artifactId
>
<
version
>
2.4
</
version
>
<
configuration
>
<
failOnMissingWebXml
>
false
</
failOnMissingWebXml
>
</
configuration
>
</
plugin
>
</
plugins
>
<
finalName
>
News_Recommend
</
finalName
>
</
build
>
</
project
>
下面來生成開發版本的jar並自動上傳到snaport倉庫
工程右鍵-->run as-->run configuration


打開nexus后台可以看到打包成功並上傳的jar:

接下來,如何生成release版本呢,只需要修改pom.xml
將
<
groupId
> News_Recommend
</
groupId
>
<
artifactId
> News_Recommend
</
artifactId
>
<
version
> 0.0.5-SNAPSHOT
</
version
>
<
packaging
> jar
</
packaging
>
改為
<
groupId
> News_Recommend
</
groupId
>
<
artifactId
> News_Recommend
</
artifactId
>
<
version
> 0.0.5
</
version
>
<
packaging
> jar
</
packaging
>
即可。
打開nexus后台查看正式版本:

工程進行正式升級時只需要在pom.xml配置新增的jar依賴包即可,如下:

原文地址:http://www.cnblogs.com/zhongshengzhen/p/nexus_maven.html
弄了兩天才有了眉目,希望對大家有用,不吝賜教和點贊,謝謝。