1 安装nexus3
查看镜像文件
docker search nexus3
拉取镜像
docker pull sonatype/nexus3
启动容器
docker run -d --restart=always --name=nexus3 -p8081:8081 --privileged=true -e INSTALL4J_ADD_VM_PARAMS="-Xms512M -Xmx512M -XX:MaxDirectMemorySize=512M" -v /mydata/nexus:/var/nexus-data sonatype/nexus3
打开neuxs3
点击右上角的登录,默认用户名是admin。查看密码,需要登录进入容器里执行如下命令
# 进入容器
docker exec -it nexus3 bash
# 查看密码
cat /nexus-data/admin.password
下图红色部分就是密码,注意,查询结果最后的bash-4.4$
不是密码部分
输入密码后回车
提示修改密码
2 批量上传本地仓库到私服
在本地仓库目录新建一个mavenimport.sh文件,内容如下
#!/bin/bash
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
while getopts ":r:u:p:" opt; do
case $opt in
r) REPO_URL="$OPTARG"
;;
u) USERNAME="$OPTARG"
;;
p) PASSWORD="$OPTARG"
;;
esac
done
find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
本地需要安装git,鼠标右键点击Open Git Bash here,然后在打开的窗口执行以下命令即可开始上传
# admin是私服用户名 admin123是私服密码
./mavenimport.sh -u admin -p admin123 -r http://192.168.119.128:8081/repository/maven-releases/
命令执行期间,可以看到私服里已经有上传上去的依赖了
查找需要的依赖,如fastjson
找到自己需要的版本,点击进去
就可以看到依赖了
3 上传单个仓库到私服
执行以下命令,将fastjson1.1.37发布到私服里
mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=fastjson-1.1.37.jar -Durl=http://localhost:8079/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty
4 setting.xml配置连接私服
setting.xml配置好后,以后就可以直接从私服下载jar包了,setting.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:\work\repositorys</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>maven-public</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>maven-public</id>
<name>maven-public</name>
<url>http://192.168.188.101:8081/repository/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<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</id>
<repositories>
<repository>
<id>maven-public</id>
<url>http://192.168.188.101:8081/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<url>http://192.168.188.101:8081/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
其中注意如下细节: