基于maven實(shí)現(xiàn)私服搭建步驟圖解
私服是架設(shè)在局域網(wǎng)的一種特殊的遠(yuǎn)程倉庫??梢源磉h(yuǎn)程倉庫以及部署第三方構(gòu)件。
有了私服之后,當(dāng)maven下載構(gòu)件時,直接請求私服,私服上存在則下載到本地倉庫。否則會請求外部的遠(yuǎn)程倉庫,將構(gòu)建下載到私服,再提供給本地倉庫下載。

構(gòu)建私服的軟件,我們這邊采用Sonatype Nexus
官網(wǎng):https://blog.sonatype.com/


解壓縮:

在bin下執(zhí)行:
./nexus.exe /run
訪問:8081端口,可以修改端口。
賬號:admin
密碼:admin123

maven-central:maven中央庫,默認(rèn)從https://repo1.maven.org/maven2/拉取jar
maven-releases:私庫發(fā)行版jar
maven-snapshots:私庫快照(調(diào)試版本)jar
maven-public:倉庫分組,把上面三個倉庫組合在一起對外提供服務(wù),在本地maven基礎(chǔ)配置settings.xml中使用。
有些jar在中心倉庫是沒有的,如oracle的驅(qū)動。
測試第三方j(luò)ar包,手動導(dǎo)入到私服中

可以看到已經(jīng)加載進(jìn)來了。

maven關(guān)聯(lián)私服
配置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一樣,這樣才可以認(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)建一個項(xià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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Mybatis-Plus讀寫Mysql的Json字段的操作代碼
這篇文章主要介紹了Mybatis-Plus讀寫Mysql的Json字段的操作代碼,文中通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
SpringBoot中實(shí)現(xiàn)@Scheduled動態(tài)定時任務(wù)
SpringBoot中的@Scheduled注解為定時任務(wù)提供了一種很簡單的實(shí)現(xiàn),本文主要介紹了SpringBoot中實(shí)現(xiàn)@Scheduled動態(tài)定時任務(wù),具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
Java基于Guava Retrying實(shí)現(xiàn)重試功能
這篇文章主要介紹了Java基于Guava Retrying實(shí)現(xiàn)重試功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07
Java Web基于Session的登錄實(shí)現(xiàn)方法
這篇文章主要介紹了Java Web基于Session的登錄實(shí)現(xiàn)方法,涉及Java針對session的操作及表單提交與驗(yàn)證技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10

