




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
Nexus搭建Maven私服+maven安裝步驟Windows下Nexus搭建Maven私服1、為什么使用Nexus
如果沒有私服,我們所需的所有構(gòu)件都需要通過maven的中央倉庫和第三方的Maven倉庫下載到本地,而一個團隊中的所有人都重復(fù)的從maven倉庫下載構(gòu)件無疑加大了倉庫的負載和浪費了外網(wǎng)帶寬,如果網(wǎng)速慢的話,還會影響項目的進程。很多情況下項目的開發(fā)都是在內(nèi)網(wǎng)進行的,連接不到maven倉庫怎么辦呢?開發(fā)的公共構(gòu)件怎么讓其它項目使用?這個時候我們不得不為自己的團隊搭建屬于自己的maven私服,這樣既節(jié)省了網(wǎng)絡(luò)帶寬也會加速項目搭建的進程,當然前提條件就是你的私服中擁有項目所需的所有構(gòu)件。
2、Nexus下載
下載地址:
3、Nexus啟動
我下載的是zip包,解壓后進入\nexus-2.1.2-bundle\nexus-2.1.2\bin\jsw\,根據(jù)操作系統(tǒng)類型選擇文件夾,我選的是windows-x86-32文件夾,進入后可看到如下所示bat文件。
雙擊運行。游覽器中輸入:8081/nexus/,出現(xiàn)圖(2)所示就代表nexus已經(jīng)啟動成功。
8081為默認的端口號,要修改端口號可進入nexus-2.1.2-bundle\nexus-2.1.2\conf\打開文件,修改application-port屬性值就可以了。默認的用戶名和密碼:admin/admin123,登錄后看到圖(3)所示:
圖(3)
4、Nexus倉庫
nexus的倉庫類型分為以下四種:
group:倉庫組
hosted:宿主
proxy:代理
virtual:虛擬
首次登陸nexus后可以看到以下一個倉庫組和多個倉庫。
PublicRepositories:
倉庫組
3rdparty:無法從公共倉庫獲得的第三方發(fā)布版本的構(gòu)件倉庫
ApacheSnapshots:用了代理ApacheMaven倉庫快照版本的構(gòu)件倉庫
Central:用來代理maven中央倉庫中發(fā)布版本構(gòu)件的倉庫
CentralM1shadow:用于提供中央倉庫中M1格式的發(fā)布版本的構(gòu)件鏡像倉庫
CodehausSnapshots:用來代理CodehausMaven倉庫的快照版本構(gòu)件的倉庫
Releases:用來部署管理內(nèi)部的發(fā)布版本構(gòu)件的宿主類型倉庫
Snapshots:用來部署管理內(nèi)部的快照版本構(gòu)件的宿主類型倉庫
、創(chuàng)建Nexus宿主倉庫在Repositories選項頁的菜單欄上點擊Add按鈕會出現(xiàn)如下所示,選擇要添加的倉庫類型。
這里我點擊添加宿主類型的倉庫,在倉庫列表的下方會出現(xiàn)新增倉庫的配置,如下所示:
點擊save按鈕后就會在倉庫列表中看到剛才新增的倉庫。、創(chuàng)建Nexus代理倉庫點擊菜單欄上的Add按鈕后選擇ProxyRepository,看到如下所示配置界面:
、創(chuàng)建Nexus倉庫組倉庫組和倉庫關(guān)系是一對多的關(guān)系,一個倉庫組可以指向多個倉庫。點擊菜單欄上的Add按鈕選擇RepositoryGroup就可以看到倉庫組的配置界面,如下所示:
點擊save后就可在倉庫列表中看到新增的倉庫組了,項目中如果要下載構(gòu)件的話,配置文件中一般都用倉庫組的URL。5、修改Maven配置文件從Nexus下載構(gòu)件1)如果想對操作系統(tǒng)的所有用戶統(tǒng)一配置maven,則只需修改maven\conf\setting.xml文件就可以了,如果只想對用戶單獨配置maven,只需將文件復(fù)制到C:\DocumentsandSettings\Administrator\.m2文件夾下(我這里假設(shè)系統(tǒng)裝在c盤,用戶為Administrator)。
2)
打開文件,可以看到如下代碼:
Java代碼<!--
localRepository
|
The
path
to
the
local
repository
maven
will
use
to
store
artifacts.
|
|
Default:
~/.m2/repository
<localRepository></localRepository>
-->
[java]\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<!--
localRepository
|
The
path
to
the
local
repository
maven
will
use
to
store
artifacts.
|
|
Default:
~/.m2/repository
<localRepository></localRepository>
-->
<!--localRepository|Thepathtothelocalrepositorymavenwillusetostoreartifacts.||Default:~/.m2/repository<localRepository></localRepository>-->
表示如果不設(shè)置localRepository,maven會默認將本地倉庫建到/.m2/repository文件夾下。設(shè)置localRepository如下代碼所示:
Html代碼<localRepository>F:\myCenterRepository</localRepository>
[html]\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<localRepository>F:\myCenterRepository</localRepository>
<localRepository>F:\myCenterRepository</localRepository>
表示在myCenterRepository文件夾下建立本地倉庫。個人建議不要采用默認的倉庫地址,因為項目如果很多的話,那么本地倉庫所占的磁盤空間就比較多了,所以指定倉庫地址到其他盤符,更方便管理。
、在POM文件中配置Nexus倉庫在項目的pom文件中添加如下代碼:
Xml代碼<repositories>
<repository>
<id>nexus</id>
<name>my-nexus-repository</name>
<url>:7788/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>my-nexus-repository</name>
<url>:7788/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
[xml]\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<repositories>
<repository>
<id>nexus</id>
<name>my-nexus-repository</name>
<url>:7788/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>my-nexus-repository</name>
<url>:7788/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<repositories><repository><id>nexus</id><name>my-nexus-repository</name><url>:7788/nexus/content/groups/public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>nexus</id><name>my-nexus-repository</name><url>:7788/nexus/content/groups/public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></pluginRepository></pluginRepositories>
在pom文件中配置只對當前項目有效,而實際開發(fā)中不可能在每個項目中重復(fù)配置信息,所以不建議在pom文件中配置。
、在文件中配置Nexus倉庫1)maven提供了profile來配置倉庫信息,如下所示:
Xml代碼<profiles>
<profile>
<id>myprofile</id>
<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>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
[xml]\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<profiles>
<profile>
<id>myprofile</id>
<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>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<profiles><profile><id>myprofile</id><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>false</enabled></snapshots></pluginRepository></pluginRepositories></profile></profiles>
2)激活profileXml代碼<activeProfiles>
<activeProfile>myprofile</activeProfile>
</activeProfiles>
[xml]\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<activeProfiles>
<activeProfile>myprofile</activeProfile>
</activeProfiles>
<activeProfiles><activeProfile>myprofile</activeProfile></activeProfiles>
3)配置鏡像Xml代碼<mirrors>
<mirror>
<id>nexus</id>
<url>:7788/nexus/content/groups/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
[xml]\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<mirrors>
<mirror>
<id>nexus</id>
<url>:7788/nexus/content/groups/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<mirrors><mirror><id>nexus</id><url>:7788/nexus/content/groups/public/</url><mirrorOf>*</mirrorOf></mirror></mirrors>
這里配置mirrorOf的值為*,代表maven的所有訪問請求都會指向到Nexus倉庫組。
6、部署構(gòu)件到Nexus倉庫、maven部署1)修改pom文件在pom文件中添加如下配置:Xml代碼<distributionManagement>
<repository>
<id>my-nexus-releases</id>
<url>:7788/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>my-nexus-snapshot</id>
<url>:7788/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
[xml]\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<distributionManagement>
<repository>
<id>my-nexus-releases</id>
<url>:7788/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>my-nexus-snapshot</id>
<url>:7788/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<distributionManagement><repository><id>my-nexus-releases</id><url>:7788/nexus/content/repositories/releases/</url></repository><snapshotRepository><id>my-nexus-snapshot</id><url>:7788/nexus/content/repositories/snapshots/</url></snapshotRepository></distributionManagement>
2)在文件中添加認證信息:Xml代碼<servers>
<server>
<id>my-nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>my-nexus-snapshot</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
[xml]\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<servers>
<server>
<id>my-nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>my-nexus-snapshot</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<servers><server><id>my-nexus-releases</id><username>admin</username><password>admin123</password></server><server><id>my-nexus-snapshot</id><username>admin</username><password>admin123</password></server></servers>
上面的配置中我用的是超級管理員的賬戶,開發(fā)項目中可以改為具有部署構(gòu)件權(quán)限的用戶就可以了。3)執(zhí)行部署測試的構(gòu)件項目信息如下:Xml代碼<groupId>com.ez</groupId>
<artifactId>TestJar</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>TestJar</name>
[xml]\o"viewplain"viewplain\o"copy"copy\o"print"print\o"?"?<groupId>com.ez</groupId>
<artifactId>TestJar</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>TestJar</name>
<groupId>com.ez</groupId><artifactId>TestJar</artifactId><version>1.0</version><packaging>jar</packaging><name>TestJar</name>
從上面的信息中可以看出構(gòu)件為發(fā)布版本,所以部署構(gòu)件的話會自動部署至releases倉庫中。
在命令行中執(zhí)行:mvncleandeploy如果之前沒用執(zhí)行過該命令,maven會自動到中央倉庫中下載部署所需的插件。最后在命令行中看到如下所示就代表構(gòu)件已經(jīng)部署成功。
到nexus的releases倉庫中查看剛剛部署好的構(gòu)件信息如下所示:
如果部署失敗的要檢查一下用戶是否有部署的權(quán)限,目標倉庫是否允許部署,是否缺少部署所需的構(gòu)件。、手動部署手動部署構(gòu)件則更為簡單了,在nexus的倉庫列表中點擊要部署的目標倉庫,然后點擊ArtifactUpload選項卡看到下圖所示:
通過以上配置運用Nexus搭建的私服基本上可以用了,更多配置需求可參考Nexusbook.maven安裝步驟第一步:配置maven環(huán)境
maven3安裝:
安裝Maven之前要求先確定你的JDK已經(jīng)安裝配置完成。Maven是Apache下的一個項目,目前最新版本是,我用的也是這個。
首先去官網(wǎng)下載Maven:
下載完成之后將其解壓,我將解壓后的文件夾重命名成maven,并將它放在D:\Server目錄下,即maven最終的路徑是:D:\Server\maven
配置maven環(huán)境變量:
系統(tǒng)變量:MAVEN_HOME
=D:\Server\maven
用戶變量:path=%MAVEN_HOME%\bin
相信大家都有配過環(huán)境變量的,詳細步驟就不說了,對著把屬性名和屬性值配上的OK了。
打開cmd,在里面敲:mvn-version
如果能打印如上信息,說明到此Maven3已經(jīng)在你的電腦上安裝完成。
mvn是mavn的一個指令,mvn-version是查看版本信息,我的操作系統(tǒng)是32位的WIN7,安裝的maven是
如果能打印如上信息,說明到此Maven3已經(jīng)在你的電腦上安裝完成.打開命令提示符(開始---運行---cmd),檢查我們的java環(huán)境和maven環(huán)境是否有誤。
第二步:修改倉庫位置
修改我們倉庫地址,倉庫用于存放我們項目所依賴的所有jar包。我的倉庫路徑:F:\maven\repo----這個路徑是我自己創(chuàng)建,你可以將路徑創(chuàng)建在任何位置。我們打開…\apache-maven-3.0.3\conf\目錄下的文件,設(shè)置成我們創(chuàng)建的倉庫路徑下面我們用一個命令驗證一下。打開命令提示符,輸入:mvn
help:system
該命令會打印出所有的java系統(tǒng)屬性和環(huán)境變量。這些信息對我們?nèi)粘5木幊坦ぷ骱苡袔颓?。如果運行的過程中沒有錯誤,打開我們倉庫(F:\maven\repo)會發(fā)現(xiàn)里面多了一些文件。這些文件就是我們從maven的中央倉庫下載到本地倉庫的。
第三步:創(chuàng)建maven項目創(chuàng)建一個我們自己的項目。我們通過maven命令行方式創(chuàng)建一個項目
因為是第一次構(gòu)建項目,所有依賴的jar包都要從maven的中央倉庫下載,所以需要時間等待。等以后我們的本地倉庫中積累了我們常用的jar包后,我們的開發(fā)將變得非常規(guī)范和方便。^_^!!
借助下載jar包的時間,我們來了解一下文件。<projectxmlns="/POM/4.0.0"xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/POM/4.0.0/xsd/maven-4.0.0.xsd"><modelVersion></modelVersion><groupId></groupId><artifactId>hello</artifactId><version></version><packaging>jar</packaging><name>hello</name><url></url><properties><>UTF-8</></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version></version><scope>test</scope></dependency></dependencies></project>?
project:文件中的頂層元素;
?
modelVersion:指明POM使用的對象模型的版本。這個值很少改動。
?
groupId:指明創(chuàng)建項目的組織或者小組的唯一標識。GroupId是項目的關(guān)鍵標識,典型的,此標識以組織的完全限定名來定義。比如,是所有Maven插件項目指定的groupId。
?
artifactId:指明此項目產(chǎn)生的主要產(chǎn)品的基本名稱。項目的主要產(chǎn)品通常為一個JAR文件。第二,象源代碼包通常使用artifactId作為最后名稱的一部分。典型的產(chǎn)品名稱使用這個格式:
<artifactId>-
<version>.
<extension>(比如:myapp-1.0.jar)。
?
version:項目產(chǎn)品的版本號。Maven幫助你管理版本,可以經(jīng)??吹絊NAPSHOT這個版本,表明項目處于開發(fā)階段。
?
name:項目的顯示名稱,通常用于maven產(chǎn)生的文檔中。
?
url:指定項目站點,通常用于maven產(chǎn)生的文檔中。
?
description:描述此項目,通常用于maven產(chǎn)生的文檔中。
對于一個項目中只有下面的一部分是是我們需要關(guān)注的:<groupId>com.chongshi.test</groupId>
<artifactId>hello</artifactId>
<version>1.0</version>
第四步:編譯項目代碼我們的項目已經(jīng)創(chuàng)建完成。但我們點開目錄發(fā)現(xiàn),它并不是我們eclipse所需要的項目目錄格式。我們需要把它構(gòu)建成我們eclipse可以導(dǎo)入的項目。在命令提示符下進入到我們的創(chuàng)建的項目目錄(F:\maven\hello)下,執(zhí)行:mvn
clean
compileClean
告訴maven清理輸入出目錄target/,compile告訴maven編譯項目主代碼。不要急,我們又需要一段時間來下載,相關(guān)jar包。^_^!第一次用maven要學(xué)會淡定。
項目是編譯完了,但項目的目錄結(jié)構(gòu)還不是我們想要的eclipse的項目結(jié)構(gòu),是不能導(dǎo)入到eclipse中的。所以,還需要執(zhí)行一個命令:mvn
eclipse:eclipse
命令執(zhí)行完成后就得我們需要的項目目錄了。
第五步:導(dǎo)入eclipse工具
打開的我們的eclipse工具。先配置maven倉庫路徑Window----Perferences-----java-----Build
Path-----Classpath
VariablesNew一個變量的類路徑。Name
:M2_REPO
注意這個名字必須要大寫。Path
:F:/maven/repo
點擊“Folder…”找到有本地倉庫的位置。
下面,可以導(dǎo)入我的hello項目了。Eclipse如何導(dǎo)入項目,我這里就不說了,如果你是個java開發(fā)人員的話。
第六步:包的更新與下載
打開項目發(fā)現(xiàn)我們junit
是的,有點老了。那我想換成的,如何通過maven的方式更換呢。其實,很簡單,打開我們項目下的的文件?!?lt;dependencies><depen
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度餐飲經(jīng)營合作補充協(xié)議
- 二零二五年度環(huán)??萍柬椖亢匣锶藚f(xié)議
- 二零二五年度商業(yè)連鎖委托經(jīng)營管理合同
- 2025年度航空物流就業(yè)實習(xí)協(xié)議書
- 二零二五年度廚師職業(yè)保險及福利保障協(xié)議
- 二零二五年度單位合同管理及企業(yè)合規(guī)經(jīng)營保障協(xié)議
- 二零二五年度水利工程水管安裝與生態(tài)平衡合同
- 二零二五年度測繪成果保密保護措施合同
- 2025年度老舊小區(qū)改造工程包工不包料施工合同
- 二零二五年度房地產(chǎn)抵押借款貸后監(jiān)管服務(wù)合同
- 中醫(yī)推拿療法(推拿技術(shù))
- 汕頭大學(xué)匯報模板
- 拼音拼讀音節(jié)帶聲調(diào)完全版
- 環(huán)泊酚注射液-臨床用藥解讀
- 冷庫安全檢查內(nèi)容與評價標準
- (完整版)4.19天體運動綜合習(xí)題(帶答案)
- 放射科未來五年發(fā)展規(guī)劃(2021-2025)
- 中學(xué)生預(yù)防性侵主題班會
- 不良資產(chǎn)項目律師法律盡調(diào)報告(模板)
- 高級技校電氣自動化設(shè)備安裝與維修教學(xué)計劃
- 《長征之戰(zhàn)役》課件
評論
0/150
提交評論