1.獲取nexus3鏡像java
docker pull sonatype/nexus3
2.建立啓動nexus3容器web
docker run -dit -p 8081:8081 --name nexus -v /root/nexus-data:/var/nexus-data --restart=always sonatype/nexus3
參數說明spring
3.訪問nexus
在瀏覽器輸入:http://ip:8081便可看到如下頁面:(ip爲遠程主機的ip地址) docker
用初始密碼admin/admin123登陸,發現報出:Your admin user password is located in /nexus-data/admin.password on the server.apache
意思是admin用戶密碼在/nexus-data/admin.password 文件中,那麼接下來我就須要找到這個文件問題就解決了。瀏覽器
進入nexus容器springboot
docker exec -it nexus /bin/bash
使用這個命令找到這個文件地址bash
find / -name 'admin.password'
拿着上圖這個初始密碼,點擊右上方的Sign in進行登陸maven
能夠看到默認狀況下Nexus會幫咱們建立了幾個倉庫,仔細觀察紅色框住的地方,裏面有幾種倉庫的類型,解釋以下:ide
下面咱們仔細看一下里面的一些倉庫,點擊maven-central倉庫:
能夠看到是一個proxy類型的倉庫,默認代理的遠程倉庫地址是https://repo1.maven.org/maven2/,這裏把它改成阿里雲http://maven.aliyun.com/nexus...
進入maven-public查看
能夠看到這是一個group類型的倉庫,裏面包含了maven-releases/maven-snapshots/maven-central倉庫,意思是咱們只須要在本地添加這個倉庫,則能夠依賴到上述3個倉庫中的庫了。
1.建立一個新的倉庫(也能夠選用已經存在的倉庫)
建立倉庫,點擊Create repository,而後選擇maven2(hosted)而後輸入倉庫名稱(test-release)。在version policy中選擇這個倉庫的類型,這裏選擇release,在Deployment policy中選擇Allow redeploy(這個很重要)
2.修改本地D:Program Files (x86)apache-maven-3.2.3conf目錄下的settings.xml
<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>releases</id> <username>admin</username> <password>123456</password> </server> </servers>
3.用IDEA搭建springboot項目,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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>docker</artifactId> <name>docker</name> <description>Demo project for Spring Boot</description> <!--注意限定版本必定爲RELEASE,由於上傳的對應倉庫的存儲類型爲RELEASE--> <version>1.0-RELEASE</version> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <!--指定倉庫地址--> <distributionManagement> <repository> <!--此名稱要和settings.xml中設置的ID一致--> <id>releases</id> <url>http://139.9.40.41:8081/repository/test-release/</url> </repository> </distributionManagement> <build> <plugins> <!--發佈代碼Jar插件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> </plugin> <!--發佈源碼插件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
打開終端,輸入mvn deploy,若報出mvn不是內部命令,可參考
https://blog.csdn.net/sz15732...,最後用管理職身份再次運行IDEA。
上傳成功,回到Nexus的網頁中查看結果
用IDEA新建一個springboot工程,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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>test</artifactId> <version>0.0.1-SNAPSHOT</version> <name>test</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>docker</artifactId> <version>1.0-RELEASE</version> </dependency> </dependencies> <repositories> <repository> <id>releases</id> <url>http://139.9.40.41:8081/repository/test-release/</url> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
最後發現jar依賴成功