docker-compose 搭建 nexus3 以及在項目中的使用
docker-compose 搭建 nexus3
默認docker docker-compose 安裝完成
[root@MiWiFi-R3P-srv nexus] pwd
/usr/local/docker/nexus
[root@MiWiFi-R3P-srv nexus] ls
data docker-compose.yml
[root@MiWiFi-R3P-srv nexus] cat docker-compose.yml
version: "3.1"
services:
nexus3:
image: 192.168.31.185:5000/sonatype/nexus3
container_name: nexus3
ports:
- "8081:8081"
volumes:
- /usr/local/docker/nexus/data:/nexus-data #這裏的./data請自行改成自己創建的文件夾的路徑
restart: always
privileged: true
[root@MiWiFi-R3P-srv nexus] chmod 777 data/
#啓動
[root@MiWiFi-R3P-srv nexus] docker-compose up -d
#查看日誌
[root@MiWiFi-R3P-srv nexus] docker-compose logs -f nexus3
[root@MiWiFi-R3P-srv nexus] docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b7f729997747 192.168.31.185:5000/sonatype/nexus3 "sh -c ${SONATYPE_..." 15 minutes ago Up 12 minutes 0.0.0.0:8081->8081/tcp nexus3
搭建成功,根據提示查看密碼
[root@MiWiFi-R3P-srv nexus] pwd
/usr/local/docker/nexus
[root@MiWiFi-R3P-srv nexus] ls
data docker-compose.yml
[root@MiWiFi-R3P-srv nexus] cd data/
[root@MiWiFi-R3P-srv data] cat admin.password
33a2e3db-78a3-467a-9f9b-9a6bf0c041df
按照提示初始化,搭建成功
maven 私服的在項目中的使用
怎樣像使用阿里雲公共倉庫一樣使用私服
在maven配置文件添加私服地址
光配置這個地址還是不行的,我們私服是需要賬號密碼登錄的,所以要添加一個服務,上面配置的私服id要和server中的id相同(id可以隨便定義,重要的是要一致)
上一下完整的配置文件(去除註釋後剩餘的)
<?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">
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>12345678</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>12345678</password>
</server>
<server>
<id>nexus-local</id>
<username>admin</username>
<password>12345678</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-local</id>
<mirrorOf>*</mirrorOf>
<name>Nexus osc</name>
<url>http://192.168.31.12:80/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
</profiles>
</settings>
然後就可以通過私服下載依賴了
如你的無法依賴到的話看看這個可能有幫助
maven 私服 nexus3 配置,使用,踩坑!!!
自己寫的jar包發佈到nexus
上面配置文件還有如下兩個服務,nexus-releases 發行版,nexus-snapshots 快照版,這兩個會用到,先配置上,
然後就是在項目裏配置pom文件了
pom文件添加distributionManagement節點
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.31.12:80/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.31.12:80/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
部署到私服 mvn deploy
cool@cools-iMac-Pro spring-mvc-xml % mvn deploy
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< learn:spring-mvc-xml >------------------------
[INFO] Building spring-mvc-xml Maven Webapp 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ spring-mvc-xml ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ spring-mvc-xml ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ spring-mvc-xml ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/cool/Desktop/manage_boot/spring-mvc-xml/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ spring-mvc-xml ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ spring-mvc-xml ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:3.2.0:war (default-war) @ spring-mvc-xml ---
[INFO] Packaging webapp
[INFO] Assembling webapp [spring-mvc-xml] in [/Users/cool/Desktop/manage_boot/spring-mvc-xml/target/spring-mvc-xml]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/cool/Desktop/manage_boot/spring-mvc-xml/src/main/webapp]
[INFO] Webapp assembled in [82 msecs]
[INFO] Building war: /Users/cool/Desktop/manage_boot/spring-mvc-xml/target/spring-mvc-xml.war
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ spring-mvc-xml ---
[INFO] Installing /Users/cool/Desktop/manage_boot/spring-mvc-xml/target/spring-mvc-xml.war to /Users/cool/.m2/repository/learn/spring-mvc-xml/1.0-SNAPSHOT/spring-mvc-xml-1.0-SNAPSHOT.war
[INFO] Installing /Users/cool/Desktop/manage_boot/spring-mvc-xml/pom.xml to /Users/cool/.m2/repository/learn/spring-mvc-xml/1.0-SNAPSHOT/spring-mvc-xml-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ spring-mvc-xml ---
Downloading from nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/1.0-SNAPSHOT/maven-metadata.xml
Downloaded from nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/1.0-SNAPSHOT/maven-metadata.xml (763 B at 5.8 kB/s)
Uploading to nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/1.0-SNAPSHOT/spring-mvc-xml-1.0-20200405.122934-2.war
Uploaded to nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/1.0-SNAPSHOT/spring-mvc-xml-1.0-20200405.122934-2.war (6.6 MB at 21 MB/s)
Uploading to nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/1.0-SNAPSHOT/spring-mvc-xml-1.0-20200405.122934-2.pom
Uploaded to nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/1.0-SNAPSHOT/spring-mvc-xml-1.0-20200405.122934-2.pom (5.9 kB at 156 kB/s)
Downloading from nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/maven-metadata.xml
Downloaded from nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/maven-metadata.xml (277 B at 17 kB/s)
Uploading to nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/1.0-SNAPSHOT/maven-metadata.xml
Uploaded to nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/1.0-SNAPSHOT/maven-metadata.xml (763 B at 19 kB/s)
Uploading to nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/maven-metadata.xml
Uploaded to nexus-snapshots: http://192.168.31.12:80/repository/maven-snapshots/learn/spring-mvc-xml/maven-metadata.xml (277 B at 7.9 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.182 s
[INFO] Finished at: 2020-04-05T20:29:34+08:00
[INFO] ------------------------------------------------------------------------
查看一下
下載私服快照上的jar
pom文件增加依賴並配置repositories
<dependency>
<groupId>learn</groupId>
<artifactId>base</artifactId>
<version>1.0-20200405.125031-1</version>
</dependency>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.31.12:80//nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.31.12:80nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
上傳三方jar包