基于maven實(shí)現(xiàn)私服搭建步驟圖解
私服是架設(shè)在局域網(wǎng)的一種特殊的遠(yuǎn)程倉庫。可以代理遠(yuǎn)程倉庫以及部署第三方構(gòu)件。
有了私服之后,當(dāng)maven下載構(gòu)件時(shí),直接請(qǐng)求私服,私服上存在則下載到本地倉庫。否則會(huì)請(qǐng)求外部的遠(yuǎn)程倉庫,將構(gòu)建下載到私服,再提供給本地倉庫下載。
構(gòu)建私服的軟件,我們這邊采用Sonatype Nexus
官網(wǎng):https://blog.sonatype.com/
解壓縮:
在bin下執(zhí)行:
./nexus.exe /run
訪問:8081端口,可以修改端口。
賬號(hào):admin
密碼:admin123
maven-central:maven中央庫,默認(rèn)從https://repo1.maven.org/maven2/拉取jar
maven-releases:私庫發(fā)行版jar
maven-snapshots:私庫快照(調(diào)試版本)jar
maven-public:倉庫分組,把上面三個(gè)倉庫組合在一起對(duì)外提供服務(wù),在本地maven基礎(chǔ)配置settings.xml中使用。
有些jar在中心倉庫是沒有的,如oracle的驅(qū)動(dòng)。
測試第三方j(luò)ar包,手動(dòng)導(dǎo)入到私服中
可以看到已經(jīng)加載進(jìn)來了。
maven關(guān)聯(lián)私服
配置maven的setting文件:
1)配置賬號(hào)密碼
|--> <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一樣,這樣才可以認(rèn)證通過。
<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)建一個(gè)項(xiàng)目,添加依賴,可以看到把我們剛才手動(dòng)加的jar給依賴過來了。
把maven項(xiàng)目部署到私服
這邊repository中配置的id需要跟maven setting中配置的server的id需要一樣。需要在本項(xiàng)目的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í)行完畢。
這邊就可以看見,跑到私服里面來了。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
IDEA 2023創(chuàng)建JSP項(xiàng)目的完整步驟教程
這篇文章主要介紹了IDEA 2023創(chuàng)建JSP項(xiàng)目的完整步驟教程,創(chuàng)建項(xiàng)目需要經(jīng)過新建項(xiàng)目、設(shè)置項(xiàng)目名稱和路徑、選擇JDK版本、添加模塊和工件、配置Tomcat服務(wù)器等步驟,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2024-10-10詳解Java如何實(shí)現(xiàn)多線程步調(diào)一致
本章節(jié)主要講解另外兩個(gè)線程同步器:CountDownLatch和CyclicBarrier的用法,使用場景以及實(shí)現(xiàn)原理,感興趣的小伙伴可以了解一下2023-07-07SpringBoot使用JWT實(shí)現(xiàn)登錄驗(yàn)證的方法示例
這篇文章主要介紹了SpringBoot使用JWT實(shí)現(xiàn)登錄驗(yàn)證的方法示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06SpringBoot集成easy-rules規(guī)則引擎流程詳解
這篇文章主要介紹了SpringBoot集成easy-rules規(guī)則引擎流程,合理的使用規(guī)則引擎可以極大的減少代碼復(fù)雜度,提升代碼可維護(hù)性。業(yè)界知名的開源規(guī)則引擎有Drools,功能豐富,但也比較龐大2023-03-03Java簡單實(shí)現(xiàn)農(nóng)夫過河問題示例
這篇文章主要介紹了Java簡單實(shí)現(xiàn)農(nóng)夫過河問題,簡單描述了農(nóng)夫過河問題的概念、原理并結(jié)合簡單實(shí)例形式分析了java解決農(nóng)夫過河問題的相關(guān)操作技巧,需要的朋友可以參考下2017-12-12