当前位置:网站首页>Nexus簡介及小白使用IDEA打包上傳到Nexus3私服詳細教程
Nexus簡介及小白使用IDEA打包上傳到Nexus3私服詳細教程
2022-07-02 17:18:00 【全棧程序員站長】
大家好,又見面了,我是你們的朋友全棧君。
使用IDEA打包上傳到Nexus3私服
一、Nexus是什麼
開始在使用Maven時,總是會聽到nexus這個詞,一會兒maven,一會兒nexus,為什麼它總是和maven一起被提到呢?
Maven作為一個優秀的構建工具、依賴管理工具、項目信息管理工具,在進行依賴管理的時候,通過pom.xml裏面的
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>來精准定比特找到對應的Java類庫。在這個過程當中我們需要從倉庫去找到對應的jar包引入到我們的項目當中,由此我們解决了合作開發中依賴增多、版本不一致、版本沖突、依賴臃腫等問題。
Maven有本地倉庫和遠程倉庫兩種,當Maven根據坐標尋找構件時,它首先會查看本地倉庫,如果本地倉庫存在此構件,則直接使用;如果本地倉庫不存在此構件,或者需要查看是否有更新的構件版本,Maven會去遠程倉庫查找,發現需要的構件之後,下載到本地倉庫再使用。
說到此,相信大家也明白了,Nexus是一種遠程倉庫,也是私服的一種。
SNAPSHOT快照版本,在 maven 中 SNAPSHOT 版本代錶正式發布(release)的版本之前的開發版本,在 pom 中用 x.y-SNAPSHOT 錶示。
RELEASE發布版本,穩定版本,在 maven 中 RELEASE 代錶著穩定的版本,unchange,不可改變的,在 maven 中 SNAPSHOT 與 RELEASE 版本在策略上是完全不同的方式,SNAPSHOT 會根據你的配置不同,頻繁的從遠程倉庫更新到本地倉庫;而 RELEASE 則只會在第一次下載到本地倉庫,以後則會先直接從本地倉庫中尋找。
二、使用Nexus3搭建maven私服
在網上找到幾個參考: Windows中使用Nexus3搭建maven私服maven 私服 nexus3.x 搭建 與使用Maven私服Nexus3.x環境構建操作記錄
三、IDEA打包上傳到Nexus3私服
1.配置 .m2 下的 settings.xml
首先,這個文件在系統盤當前設備登錄用戶的.m2文件下,加入認證機制
沒有就去網上copy一個配置好的,自己配置容易出錯
->settings.xml<-
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>rdc-releases</id>
<username>xxxxxxxxx</username>
<password>xxxxx</password>
</server>
<server>
<id>rdc-snapshots</id>
<username>xxxxxxxxx</username>
<password>xxxx</password>
</server>
</servers>1.配置 IDEA 項目 下的 pom.xml
<distributionManagement>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://xxxx:port/repository/maven-snapshots/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>maven-snapshots</name>
<url>http://xxxx:port/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>這裏標簽中的id對應第一條server中的id ,url取得值可以直接在這裏寫,也可以如下圖中settings文件中的值,name可以自定義 ->settings.xml<-
<profile>
<altReleaseDeploymentRepository> http://xxxx:port/repository/maven-snapshots/ </altReleaseDeploymentRepository>
<altSnapshotDeploymentRepository> http://xxxx:port/repository/maven-snapshots/</altSnapshotDeploymentRepository>
</profile>同樣,上面pom.xml改成如下格式
<distributionManagement>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>${altReleaseDeploymentRepository}</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>maven-snapshots</name>
<url>${altSnapshotDeploymentRepository}</url>
</snapshotRepository>
</distributionManagement>3.配置上傳地址,地址去私服中copy
<profile>
<!--profile 的 id-->
<id>dev</id>
<repositories>
<repository>
<!--倉庫 id,repositories 可以配置多個倉庫,保證 id 不重複-->
<id>nexus</id>
<!--倉庫地址,即 nexus 倉庫組的地址-->
<url>http://localhost:8081/nexus/content/groups/public/</url>
<!--是否下載 releases 構件-->
<releases>
<enabled>true</enabled>
</releases>
<!--是否下載 snapshots 構件-->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 插件倉庫,maven 的運行依賴插件,也需要從私服下載插件 -->
<pluginRepository>
<!-- 插件倉庫的 id 不允許重複,如果重複後邊配置會覆蓋前邊 -->
<id>central</id>
<name>Nexus Plugin Repository</name>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>4.其他配置(可忽略)
比如配置阿裏的鏡像,映射阿裏中央倉庫(下載jar包快一點)
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>配置本地倉庫(無需聯網使用jar包)
<localRepository>E:\maven_repository</localRepository>5.settings.xml完整配置(來源網絡,僅供參考)
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- 本地倉庫地址 -->
<localRepository>D:\mvn_repo\repository</localRepository>
<!-- 以下配置為上傳jar包配置 -->
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<!-- id,對應項目裏面pom.xml裏面distributionManagement配置的id -->
<id>maven-releases</id>
<!-- 登錄nexus的用戶名 -->
<username>admin</username>
<!-- 登錄nexus的密碼 -->
<password>admin123</password>
</server>
<server>
<!-- id,對應項目裏面pom.xml裏面distributionManagement配置的id -->
<id>maven-snapshots</id>
<!-- 登錄nexus的用戶名 -->
<username>admin</username>
<!-- 登錄nexus的密碼 -->
<password>admin123</password>
</server>
<!-- 配置攔截器mirror登錄的用戶名密碼。他會攔截所有的請求到mirror指定的地址下載jar包 如果只需要去私服下載jar包則只需配置此項 -->
<server>
<!-- id,對應mirror中id -->
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<!-- 以下配置為下載jar包配置 通用 -->
<mirrors>
<!-- 强制讓jar包下載走私服 -->
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.65.129:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<!-- 對應activeProfiles-activeProfile的內容 -->
<id>nexus</id>
<!-- 倉庫地址 -->
<repositories>
<repository>
<!-- 私服id,覆蓋maven-model模塊下的父id,讓maven不走中央倉庫下載,走私服下載 -->
<id>central</id>
<!-- 名字 -->
<name>Nexus</name>
<!-- 私服地址,寫central後,會去mirror裏面找 -->
<url>http://central</url>
<!-- 支持releases版本 -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 支持snapshots版本 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 插件地址 -->
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Nexus Plugin Repository</name>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- 配置全局的url地址 供上傳jar包時動態獲取 -->
<properties>
<ReleaseRepository>http://192.168.65.129:8081/repository/maven-releases/</ReleaseRepository>
<SnapshotRepository>http://192.168.65.129:8081/repository/maven-snapshots/</SnapshotRepository>
</properties>
</profile>
</profiles>
<!-- 選擇使用的profile -->
<activeProfiles>
<activeProfile>nexus</activeProfile>
<!-- <activeProfile>rdc</activeProfile>-->
</activeProfiles>
</settings>6.IDEA打包上傳
使用idea打包,打包時會根據pom文件中version判斷是快照版本還是發布版本,version中0.0.1-SNAPSHOT 帶SNAPSHOT為快照版本,删掉SNAPSHOT為發布版本,上傳到私服時根據version自動判斷上傳到哪個倉庫
注意,打包時 項目的pom文件一定要把maven-plugin删除掉,不然打包完成後會生成BOOT-INF文件夾,會造成上傳到私服後,配置依賴後能下載到jar包,但是使用時報包找不到錯誤
<version>1.1-SNAPSHOT</version>
<build>
</build>然後clean後deploy
看到BUILD SUCCESS的提示則為成功,可以在自己私服上查看
發布者:全棧程序員棧長,轉載請注明出處:https://javaforall.cn/148092.html原文鏈接:https://javaforall.cn
边栏推荐
- 一文看懂:数据指标体系的4大类型
- 关于举办科技期刊青年编辑沙龙——新时代青年编辑应具备的能力及提升策略的通知...
- VMware安装win10镜像
- 剑指 Offer 25. 合并两个排序的链表
- Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
- 博客主题 “Text“ 夏日清新特别版
- Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era
- DGraph: 大规模动态图数据集
- P6774 [NOI2020] 时代的眼泪(分块)
- Sword finger offer 27 Image of binary tree
猜你喜欢

Sword finger offer 26 Substructure of tree

Believe in yourself and finish the JVM interview this time

Executive engine module of high performance data warehouse practice based on Impala

Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia

亚马逊云科技 Community Builder 申请窗口开启

Just a coincidence? The mysterious technology of apple ios16 is even consistent with the products of Chinese enterprises five years ago!

Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers

OpenHarmony如何启动远程设备的FA

伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO

QStyle实现自绘界面项目实战(二)
随机推荐
In MySQL and Oracle, the boundary and range of between and precautions when querying the date
使用知行之桥的API端口,提供资源供合作伙伴访问
【Leetcode】13. 罗马数字转整数
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
What is generics- Introduction to generics
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
剑指 Offer 25. 合并两个排序的链表
Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
【Leetcode】13. Roman numeral to integer
P6774 [NOI2020] 时代的眼泪(分块)
Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion
绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东
Executive engine module of high performance data warehouse practice based on Impala
Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
Method of C language self defining function
ETH数据集下载及相关问题
Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era
AP and F107 data sources and processing
Domestic relatively good OJ platform [easy to understand]
剑指 Offer 27. 二叉树的镜像