Maven發(fā)布項目 (jar包) 到Nexus私服中的操作
1 需求說明
開發(fā)完項目后, 將項目版本發(fā)布到Nexus私服中.
2 實現(xiàn)步驟
2.1 Maven服務的setting.xml文件
(1) 如果本機安裝了Maven服務, 可在${MAVEN_HOME}/conf/setting.xml中指定私服相關(guān)的配置:
<!-- 在servers標簽下配置server, 包括: 私服的用戶名和密碼, 在deploy項目時需要用到 --> <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server> <!-- 在profiles標簽下配置profile, 包括: 私服所配的倉庫、各個插件的倉庫地址 --> <profile> <!-- profile的id --> <id>dev</id> <repositories> <repository> <!-- 倉庫id, Repositories可以配置多個倉庫, 要確保id不重復 --> <id>nexus</id> <!-- 倉庫地址, 即nexus倉庫組的地址 --> <url>http://ip:port/nexus/content/groups/public/</url> <!-- 是否下載Releases構(gòu)件 --> <releases> <enabled>true</enabled> </releases> <!-- 是否下載Snapshots構(gòu)件 --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <!-- 插件倉庫, Maven的運行依賴插件, 也需要從私服下載插件 --> <pluginRepository> <!-- 插件倉庫的id不允許重復, 如果重復, 后配置的優(yōu)先 --> <id>public</id> <name>Public Repositories</name> <url>http://ip:port/nexus/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile> <!-- 還需指定聯(lián)網(wǎng)倉庫, 保證本私服中沒有相關(guān)jar包或插件時可聯(lián)網(wǎng)獲取 --> <profile> <id>internet</id> <repositories> <repository> <id>nexus-aliyun</id> <name>Nexus aliyun</name> <layout>default</layout> <!-- 這里配置阿里云的倉庫 --> <url>http://maven.aliyun.com/nexus/content/groups/public</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories> </profile>
(2) 如果本機沒有安裝Maven服務, 可在IDEA或Eclipse等開發(fā)環(huán)境默認使用的Maven配置中修改, 修改內(nèi)容同上.
2.2 項目的pom.xml文件
在項目的pom.xml中的一級標簽project下添加如下內(nèi)容:
<!-- 發(fā)布選項: id必須與setting.xml文件中server的id相同 --> <distributionManagement> <repository> <id>releases</id> <name>display</name> <url>http://ip:port/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>display</name> <url>http://ip:port/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
2.3 發(fā)布項目
以IDEA為例, 選中項目, 右鍵 -> Run Maven -> deploy,
或者在右邊欄選中Maven欄目, 點擊項目 -> Lifecycle -> deploy, 執(zhí)行即可將項目發(fā)布到倉庫中去.
注意:倉庫中不能存在與當前項目名稱+版本號相同的項目, 否則將導致出錯: Bad Request: 400.
補充知識:maven上傳jar包到nexus私服后的存放路徑 以及 使用IDEA上傳jar包的步驟
maven上傳jar包到nexus私服的方法,網(wǎng)上大神詳解很多,那么上傳后的jar包存放到哪里了呢?
在下使用nexus3.2.1版本,在本地搭建了私服,使用maven上傳jar包。最后結(jié)果如下:
點進去后展示的是:
這讓我一度以為是以jar包的形式保存在本地,但事實證明,保存在本地的最終是一個 .bytes 類型的文件,它的默認路徑在\nexus-3.2.1-01-win64\sonatype-work\nexus3\blobs\default\content下面
即使jar包是同樣的,但是deploy了兩次,那么就會展示兩次
nexus設置自定義路徑時,要設置Blob Stores,默認只有default一個,新建一個路徑的話就可以自己指定了
簡單說下在搭建好nexus私服以后,將jar包上傳到私服的步驟
場景:使用IDEA,maven項目打jar包后上傳
在pom.xml文件中配置
<distributionManagement> <repository> <id>nexus</id> <name>maven-releases</name> <url>http://localhost:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus</id> <name>maven-snapshots</name> <url>http://localhost:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
<id>標簽對應著 maven的配置文件setting.xml中<server>的設置,如下:
<servers> <server> <id>nexus</id> <username>admin</username> <password>admin123</password> </server> </servers>
最后使用deploy操作,將打好的jar包上傳到nexus私服上
以上這篇Maven發(fā)布項目 (jar包) 到Nexus私服中的操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java Spring @Autowired的這些騷操作,你都知道嗎
這篇文章主要介紹了徹底搞明白Spring中的自動裝配和Autowired注解的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2021-09-09淺析Java中XPath和JsonPath以及SpEL的用法與對比
XPath,即XML路徑語言,是一種用于在XML文檔中查找信息的語言,JsonPath是從XPath中發(fā)展而來的,專門用于JSON數(shù)據(jù)格式,本文主要來講講他們的用法與區(qū)別,需要的可以參考下2023-11-11SpringBoot整合Shiro框架,實現(xiàn)用戶權(quán)限管理
Apache Shiro是一個強大且易用的Java安全框架,執(zhí)行身份驗證、授權(quán)、密碼和會話管理。作為一款安全框架Shiro的設計相當巧妙。Shiro的應用不依賴任何容器,它不僅可以在JavaEE下使用,還可以應用在JavaSE環(huán)境中。2021-06-06Java Vector實現(xiàn)班級信息管理系統(tǒng)
這篇文章主要為大家詳細介紹了Java Vector實現(xiàn)班級信息管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02Java使用NioSocket手動實現(xiàn)HTTP服務器
本篇文章主要介紹了Java使用NioSocket手動實現(xiàn)HTTP服務器,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-05-05