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依赖成功