基于maven實現私服搭建步驟圖解
私服是架設在局域網的一種特殊的遠程倉庫??梢源磉h程倉庫以及部署第三方構件。
有了私服之后,當maven下載構件時,直接請求私服,私服上存在則下載到本地倉庫。否則會請求外部的遠程倉庫,將構建下載到私服,再提供給本地倉庫下載。
構建私服的軟件,我們這邊采用Sonatype Nexus
解壓縮:
在bin下執(zhí)行:
./nexus.exe /run
訪問:8081端口,可以修改端口。
賬號:admin
密碼:admin123
maven-central:maven中央庫,默認從https://repo1.maven.org/maven2/拉取jar
maven-releases:私庫發(fā)行版jar
maven-snapshots:私庫快照(調試版本)jar
maven-public:倉庫分組,把上面三個倉庫組合在一起對外提供服務,在本地maven基礎配置settings.xml中使用。
有些jar在中心倉庫是沒有的,如oracle的驅動。
測試第三方jar包,手動導入到私服中
可以看到已經加載進來了。
maven關聯私服
配置maven的setting文件:
1)配置賬號密碼
|--> <servers> <!-- server | Specifies the authentication information to use when connecting to a particular server, identified by | a unique name within the system (referred to by the 'id' attribute below). | | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are | used together. | <server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server> --> <!-- Another sample, using keys to authenticate. <server> <id>siteServer</id> <privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave empty if not used.</passphrase> </server> --> <server> <id>nexus-public</id> <username>admin</username> <password>admin123</password> </server> </servers>
2)配置profile, 在<profiles></profiles>中添加, 這邊配置repository的id需要跟上面的server配置的id一樣,這樣才可以認證通過。
<profile> <id>nexus</id> <repositories> <repository> <id>nexus-public</id> <name>private reposity</name> <url>http://localhost:8081/repository/maven-public/</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile>
3)使profile生效
<activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
創(chuàng)建一個項目,添加依賴,可以看到把我們剛才手動加的jar給依賴過來了。
把maven項目部署到私服
這邊repository中配置的id需要跟maven setting中配置的server的id需要一樣。需要在本項目的pom.xml添加如下配置。
<distributionManagement> <repository> <id>nexus-public</id> <name>core release repository</name> <url>http://localhost:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-public</id> <name>core snapshots repository</name> <url>http://localhost:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
執(zhí)行命令:
mvn deploy
需要等待執(zhí)行完畢。
這邊就可以看見,跑到私服里面來了。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
IDEA 2023創(chuàng)建JSP項目的完整步驟教程
這篇文章主要介紹了IDEA 2023創(chuàng)建JSP項目的完整步驟教程,創(chuàng)建項目需要經過新建項目、設置項目名稱和路徑、選擇JDK版本、添加模塊和工件、配置Tomcat服務器等步驟,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2024-10-10SpringBoot集成easy-rules規(guī)則引擎流程詳解
這篇文章主要介紹了SpringBoot集成easy-rules規(guī)則引擎流程,合理的使用規(guī)則引擎可以極大的減少代碼復雜度,提升代碼可維護性。業(yè)界知名的開源規(guī)則引擎有Drools,功能豐富,但也比較龐大2023-03-03