本地私服可以: 上傳jar包共享,還可以上傳項目共享,可供局域網使用
本文使用maven版本: 3.3.9
度盤鏈接:https://pan.baidu.com/s/1DpyEoav9FcJs2v4H5Pu9-g
提取碼:sl08
1.下載nexus官方壓縮包
http://www.sonatype.org/nexus/go找到對應操作系統的版本下載,
本文下載得到的版本是: nexus-3.19.1-01-win64.zip
度盤鏈接:https://pan.baidu.com/s/1gSmEXm15KYoXd-YE5pwK4Q
提取碼:amb0
2.解壓
nexus-3.19.1-01-win64
3.運行
1. nexus.exe /run 命令可以啓動nexus服務(參考官方文檔)
2. 安裝nexus本地服務來啓動(推薦使用這種方式,參考官方文檔),命令如下所示。
nexus.exe /install <optional-service-name> //安裝nexus服務,一般不指定服務名稱,默認爲nexus
nexus.exe /start <optional-service-name> //啓動nexus服務或cmd後執行net start nexus
nexus.exe /stop <optional-service-name> //停止nexus服務或cmd後執行net stop nexus
我們先臨時使用第一種方法啓動(可以觀察啓動有沒有報錯,後再註冊爲服務):
cmd進入真實目錄: nexus-3.19.1-01-win64\nexus-3.19.1-01\bin
執行啓動命令: nexus.exe /run
第一次啓動會比較慢,默認登錄地址是http://localhost:8081,你能打開這個地址說明就啓動成功了
如果不成功就看報錯
可以打開文件nexus-3.19.1-01-win64\nexus-3.19.1-01\etc\nexus-default.properties修改默認端口8081
4.登錄
默認登錄地址http://localhost:8081,輸入用戶名admin和密碼admin123,點登錄,會提示你密碼錯誤,並告訴你初始密碼的位置,
找到初始密碼進行登錄,系統會提示你修改密碼,可以修改爲admin123或其他密碼5.配置本地maven指向本地私服
啓動之後,系統默認會生成兩個公共庫: maven和nuget, 如果不想新建,可以使用默認的
如果使用默認的, 我們修改maven/conf/settings.xml指向私服地址
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
6.註冊maven沒有的jar包,入sqljdbc4,ojdbc14等
註冊sqljdbc4:
由於微軟沒有提供sqljdbc4的maven座標,所以需要自己下載jar包進行添加依賴
sqljdbc4的jar包微軟的官方下載地址
http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774
度盤鏈接:https://pan.baidu.com/s/11UTtmYL_96U5FU9-_6b35Q
提取碼:hifz
註冊到本地私服倉庫
1.命令行(推薦)
mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0
2.界面上Upload
這樣就可以在pom.xlm引用了
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
卸載sqljdbc4
語法:
mvn dependency:purge-local-repository -DmanualInclude="groupId:artifactId, ..."
實際:
mvn dependency:purge-local-repository -DmanualInclude="com.microsoft.sqlserver:sqljdbc4"
7.新建自己的倉庫,命名按maven倉庫來
需要新建group(倉庫組),hosted(宿主倉庫),proxy(代理倉庫)
proxy:即設置代理,在你的nexus中找不到的依賴就會去代理的地址中找
hosted:你可以上傳你自己的項目到這裏面
group:它可以包含前面兩個,是一個聚合體。一般用來給客戶一個訪問nexus的統一地址
Create repository->maven2(hosted)->my-releases : 其中Hosted的Deployment policy選擇Allow redeploy
Create repository->maven2(proxy)->my-central : 其中在Enter a URL寫默認地址https://repo1.maven.org/maven2即可
Create repository->maven2(group)->my-public : 其中Group下的Available全部選擇到右邊或只選上面兩項即可
這樣就創建好自己的倉庫了,如果要使用自己的倉庫地址,只需要將上面的mirror的url指定爲
http://localhost:8081/repository/my-public/
即可
8.發佈自己的maven項目到私服
<distributionManagement>
<repository>
<id>my-project-releases</id>
<name>my-project</name>
<url>http://localhost:8081/repository/maven-public/</url>
</repository>
</distributionManagement>
發佈命令:
mvn clean deploy -X -Dmaven.test.skip=true
然後就可以添加依賴了
9.如果公司通過代理上網給 Maven設置代理如下
在settings.xml 中添加代理設置
<proxies>
<proxy>
<id>company-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>88.110.0.120</host>
<port>8099</port>
</proxy>
</proxies>