Nexus3 私服搭建和配置
1,下載Nexus3,上傳至服務器
下載地址:
鏈接:https://pan.baidu.com/s/13G56-C8FjCt2pRMx5BOrTQ
提取碼:psm7
2,添加環(huán)境變量export RUN_AS_USER=root:
[root@VM-0-6-centos nexus-3.12.0-01]# echo "export RUN_AS_USER=root" >> /etc/profile [root@VM-0-6-centos nexus-3.12.0-01]# source /etc/profile [root@VM-0-6-centos nexus-3.12.0-01]#3,啟動Nexus3
[root@VM-0-6-centos nexus-3.12.0-01]# cd bin [root@VM-0-6-centos bin]# ./nexus start WARNING: ************************************************************ WARNING: Detected execution as "root" user. This is NOT recommended! WARNING: ************************************************************ Starting nexus4,訪問系統(tǒng)并創(chuàng)建用戶、倉庫
4.1 登錄系統(tǒng)
訪問地址:http://IP:8081/nexus
默認端口是8081
默認用戶名/密碼:admin/admin123
4.2 創(chuàng)建用戶:
4.3 退出賬戶,使用剛創(chuàng)建的用戶登錄。
4.4 創(chuàng)建倉庫:
4.4.1、四種倉庫類型介紹
默認倉庫介紹
1)maven-central: maven中央庫,默認從https://repo1.maven.org/maven2/拉取jar
2)maven-releases: 私庫發(fā)行版jar
3)maven-snapshots:私庫快照(調試版本)jar
4)maven-public: 倉庫分組,把上面三個倉庫組合在一起對外提供服務,在本地maven基礎配置settings.xml中使用。
Nexus默認的倉庫類型有以下四種:(上面的名字可以隨便取,關鍵是它對應的是什么倉庫類型)
1)group(倉庫組類型):又叫組倉庫,用于方便開發(fā)人員自己設定的倉庫;
2)hosted(宿主類型):內部項目的發(fā)布倉庫(內部開發(fā)人員,發(fā)布上去存放的倉庫);
3)proxy(代理類型): 從遠程中央倉庫中尋找數據的倉庫(可以點擊對應的倉庫的Configuration頁簽下Remote Storage Location屬性的值即被代理的遠程倉庫的路徑);
4)virtual(虛擬類型): 虛擬倉庫(這個基本用不到,重點關注上面三個倉庫的使用);
Policy(策略):表示該倉庫為發(fā)布(Release)版本倉庫還是快照(Snapshot)版本倉庫;
創(chuàng)建1個proxy代理倉庫,2個hosted宿主倉庫,1個group倉庫組。
其中代理倉庫代理地址填寫阿里云:http://maven.aliyun.com/nexus/content/groups/public/
創(chuàng)建倉庫組時注意把其他幾個倉庫添加進去:
創(chuàng)建完成后的樣子:
5,將jar發(fā)送到私服上
5.1 創(chuàng)建maven項目
使用idea 創(chuàng)建一個普通的maven項目:
在項目中創(chuàng)建一個Test.java(使項目能夠打成jar包并上傳到私服上)
5.2 編輯pom.xml文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>untitled</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>demo</name><description>Demo project for Spring Boot</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><!-- 配置jar向私服推送的倉庫地址,推送時會根據版本不同推送到不同的倉庫中 --><distributionManagement><repository><id>releases</id><url>http://IP:8081/repository/java-release/</url></repository><snapshotRepository><id>snapshots</id><url>http://IP:8081/repository/java-snapshot/</url></snapshotRepository></distributionManagement> </project>5.3 編輯本地maven的setting.xml
<servers><server><id>releases</id> <!--對應pom.xml的id=releases的倉庫--><username>ciems</username><password>ciems123</password></server><server><id>snapshots</id> <!--對應pom.xml中id=snapshots的倉庫--><username>ciems</username><password>ciems123</password></server></servers><profiles><profile><!--ID用來確定該profile的唯一標識--><id>jdk-1.8</id><activation><activeByDefault>true</activeByDefault><jdk>1.8</jdk></activation><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></properties></profile><profile><id>nexus-pr</id><!-- 遠程倉庫列表 --><repositories><repository><id>nexus-xu</id><name>Nexus Central</name><!-- 虛擬的URL形式,指向鏡像的URL--><url>http://IP:8081/repository/java-group/</url><layout>default</layout><!-- 表示可以從這個倉庫下載releases版本的構件--> <releases><enabled>true</enabled></releases><!-- 表示可以從這個倉庫下載snapshot版本的構件 --> <snapshots><enabled>true</enabled></snapshots></repository></repositories><!-- 插件倉庫列表 --><pluginRepositories><pluginRepository><id>nexus-xu</id><name>Nexus Central</name><url>http://IP:8081/repository/java-group/</url><layout>default</layout><snapshots><enabled>true</enabled></snapshots><releases><enabled>true</enabled></releases></pluginRepository></pluginRepositories></profile></profiles><activeProfiles><!--需要激活 <profile>中的ID才生效--> <activeProfile>nexus-pr</activeProfile><activeProfile>jdk-1.8</activeProfile></activeProfiles>使用idea中的maven插件推送jar到私服上
查看倉庫:
6,從服務器上拉取jar文件
6.1 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:/project/shengzong/repository/repo3</localRepository><pluginGroups></pluginGroups><!-- proxies| This is a list of proxies which can be used on this machine to connect to the network.| Unless otherwise specified (by system property or command-line switch), the first proxy| specification in this list marked as active will be used.|--><proxies></proxies><servers><!--第一個nexus-xu要和下面的mirror中的id一致,代表拉取是也需要進行身份校驗--><server><id>nexus-xu</id><username>ciems</username><password>ciems123</password></server><!--這兩個前面講過,是jar上傳時候進行的驗證,id對應的是pom中id屬性的值--><server><id>releases</id> <!--對應pom.xml的id=releases的倉庫--><username>ciems</username><password>ciems123</password></server><server><id>snapshots</id> <!--對應pom.xml中id=snapshots的倉庫--><username>ciems</username><password>ciems123</password></server></servers><mirrors><mirror><id>nexus-xu</id><name>internal nexus repository</name><!--鏡像采用配置好的組的地址--><url>http://IP:8081/repository/java-group/</url><mirrorOf>!internal.repo,*</mirrorOf></mirror></mirrors><profiles><profile><!--ID用來確定該profile的唯一標識--><id>jdk-1.8</id><activation><activeByDefault>true</activeByDefault><jdk>1.8</jdk></activation><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></properties></profile><profile><id>nexus-pr</id><!-- 遠程倉庫列表 --><repositories><repository><id>nexus-xu</id><name>Nexus Central</name><!-- 虛擬的URL形式,指向鏡像的URL--><url>http://IP:8081/repository/java-group/</url><layout>default</layout><!-- 表示可以從這個倉庫下載releases版本的構件--> <releases><enabled>true</enabled></releases><!-- 表示可以從這個倉庫下載snapshot版本的構件 --> <snapshots><enabled>true</enabled></snapshots></repository></repositories><!-- 插件倉庫列表 --><pluginRepositories><pluginRepository><id>nexus-xu</id><name>Nexus Central</name><url>http://IP:8081/repository/java-group/</url><layout>default</layout><snapshots><enabled>true</enabled></snapshots><releases><enabled>true</enabled></releases></pluginRepository></pluginRepositories></profile></profiles><activeProfiles><!--需要激活 <profile>中的ID才生效--> <activeProfile>nexus-pr</activeProfile><activeProfile>jdk-1.8</activeProfile></activeProfiles> </settings>6.2 新建一個項目,并添加剛才推送上去的依賴
6.3 pom.xml 完整版
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>untitled1</artifactId><version>1.0-SNAPSHOT</version><name>demo</name><description>Demo project for Spring Boot</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.example</groupId><artifactId>untitled</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.4.0</version></plugin></plugins></build><distributionManagement><repository><id>releases</id><url>http://IP:8081/repository/java-release/</url></repository><snapshotRepository><id>snapshots</id><url>http://IP:8081/repository/java-snapshot/</url></snapshotRepository></distributionManagement> </project>6.4 查看maven 依賴是否拉取下來
6.5 調用測試是否引入成功
jar 包拉取完成
參考博文:https://www.cnblogs.com/qdhxhz/p/9808642.html
博主寫的更詳細
總結
以上是生活随笔為你收集整理的Nexus3 私服搭建和配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DNF最新纯图色脚本框架2022-4-2
- 下一篇: 预言:ALEXA工具条即将进行大规模升级