注意: nexus 3.x最新版好像不用下載索引了,目前我使用一些基本功能沒有索引也能耍的很6
下載 nexus最新版下載https://www.sonatype.com/download-oss-sonatype
然后解壓就好
安裝 安裝的時候直接雙擊bin目錄下的exe文件是無法安裝的,需要打開控制台跳轉到該路徑下,執行命令nexus.exe/run,回車之后會稍微停頓,然后出現這個就表示安裝成功了

然后打開http://localhost:8081/就看到nexus主頁了
登錄 管理員登錄,右上角的Sign in,賬號/密碼:admin admin123

創建倉庫

主要就是創建這三種類型,一開始就先創建hosted類型的,group是組是把hosted、proxy包含住的,proxy記得把倉庫鏈接換成阿里雲的
http://maven.aliyun.com/nexus/content/groups/public/

注意這里選擇Allow redeploy

上傳jar 上傳jar,圖中藍色圖標點擊后到這個頁面

那三個文件的后綴如下

下載jar 從私服下載jar
①單個項目,在pom.xml的dependencies標簽之前添加(注意:這里這樣子配置講道理是可以成功的,我偶爾也能成功,但也會失敗,不知道咋回事,所以還是推薦使用第二種方案,畢竟就算這個可以成功,一個個項目這樣子配置也太麻煩了)
另外注意看我代碼里相應注釋
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<!-- 注意:這里是nexus上自己建的倉庫地址,直接在瀏覽器中打開已經上傳有jar的倉庫的頁面,然后copy鏈接
驗證這個url能不能使用:鼠標對准,然后按住ctrl鍵,url變藍即為正確,點擊鼠標左鍵可以在瀏覽器中打開對應倉庫
如果url不能使用就無法下載jar
-->
<url>http://localhost:8081/#browse/browse:groupFirst</url>
<!-- Release版本則代表穩定的版本 -->
<releases>
<enabled>true</enabled>
</releases>
<!-- Snapshot版本代表不穩定、尚處於開發中的版本,默認關閉,需要手動啟動 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 指定插件倉庫 -->
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>nexus</name>
<url>http://localhost:8081/#browse/browse:groupFirst</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
②所有項目,直接修改setting.xml,另外注意看我代碼里相應注釋
<mirrors>
<mirror>
<id>maven-public</id>
<name>maven-public</name>
<!-- 注意:這個鏈接必須能在瀏覽器中正確跳轉到自己創建的倉庫,如果無法跳轉就下載不了jar-->
<url>http://localhost:8081/#browse/browse:groupFirst</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
擴展:setting,xml中各標簽的意義:接下來這部分內容來自於https://www.cnblogs.com/hanxiaohui/p/9420724.html
1.servers(服務器)
<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>${usr.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
id與pom.xml中distributionManagement的id保持一致,服務器標識
username和password表示服務器認證需要的用戶民和密碼
privateKey, passphrase一組密鑰 (不常用)
filePermissions, directoryPermissions如果在部署的時候會創建一個倉庫文件或者目錄,這時候就可以使用權限(不常用)
2.mirrors(鏡像)
<mirrors>
<mirror>
<id>planetmirror.com</id>
<name>PlanetMirror Australia</name>
<url>http://downloads.planetmirror.com/pub/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
設置一個中央倉庫的鏡像,看倉庫分類,也是遠程倉庫的一種配置方式。
3.profiles(構建環境) 這個可能比較難理解,maven權威指南一書中這樣說:
Profile能讓你為一個特殊的環境自定義一個特殊的構建; 構建環境的兩個例子是產品環境和開發環境。當你在開發環境中工作時,你的系統可能被配置成訪問運行在你本機的開發數據庫實例,而在產品環境中,你的系統被配置成從產品數據庫讀取數據。Maven能讓你定義任意數量的構建環境(構建profile),這些定義可以覆蓋pom.xml中的任何配置。
簡單理解就是你可以先profile中先構件好項目運行的環境,比如預設了A環境實在開發中使用,而實際上線是B環境,那么在上線的時候我們不需要一個個修改pom.xml中的配置,只需要激活改profile即可。
4.activation(激活構建環境 )
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.5</jdk>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>mavenVersion</name>
<value>2.0.3</value>
</property>
</activation>
指定profile中配置的環境在什么時候開始生效
5.activeProfiles(激活了的profile)
<activeProfiles>
<activeProfile>env-test</activeProfile>
</activeProfiles>
在setting.xml最后的一個標簽,表示env-test這個profile已被激活
