一、maven私服搭建
1.下载地址
2.启用
tar -zxvf nexus-3.31.1-01-unix.tar.gz
mv nexus-3.31.1-01 nexus3
cd nexus3/bin
./nexus start
./nexus stop
# 可以更改配置和端口
vim /usr/local/nexus3/etc/nexus-default.properties
# 初始密码位于此,更改密码后该文件将不存在
cd /usr/local/sonatype-work/nexus3/admin.password
3.配置阿里云远程代理
https://maven.aliyun.com/repository/public
-=-=-=-=-=-=-
4.设置仓库顺序
aliyun需要在central之前
3.本地配置
① 下载
- 方式一:在setting.xml文件<mirrors>标签中添加私服镜像
这里这有私服的镜像就够了,但是有时候私服网络出问题,为了我们依然能下载central类型的所以依然添加了阿里云镜像,不过这里阿里云下载central类型的包时优先级比私服高
<!-- 私服仓库 -->
<mirror>
<id>nexus-maven</id>
<mirrorOf>*</mirrorOf>
<name>nexus maven</name>
<url>http://ip:8081/repository/maven-public/</url>
</mirror>
<!-- 阿里公共仓库-->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
在setting.xml文件<profiles>标签中添加仓库配置
<!-- maven repo -->
<profile>
<id>nexusmaven</id>
<repositories>
<repository>
<id>nexus-maven</id>
<url>http://ip:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-maven</id>
<url>http://ip:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
在setting.xml文件<activeProfiles>标签中激活上面的仓库配置
<activeProfiles>
<activeProfile>nexusmaven</activeProfile>
</activeProfiles>
- 方式二:pom中添加仓库配置
<repositories>
<repository>
<id>nexus-maven</id>
<url>http://ip:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-maven</id>
<url>http://ip:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
② 上传
在setting.xml文件<servers>标签中添加仓库节点账号密码
<server>
<id>releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
- 方式一:上传打包项目在此项目pom文件中添加(这里的id一定要和上面server节点id一致)
<distributionManagement>
<repository>
<id>releases</id>
<url>http://ip:port/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://ip:port/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
随后点击clear、deploy即可
- 方式二:命令上传
mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=10.2.0.1.0 -Dpackaging=jar -Dfile=D:\\aa\\bb.jar -Durl=http://ip:8081/repository/maven-releases/ -DrepositoryId=nexus
- 方式三:批量上传
mavenimport.sh
# end 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}/{} ;nabled=1
启动脚本
./maven-import.sh -u admin -p admin -r http://ip:8081/repository/maven-releases/
sleep 1
./maven-import.sh -u admin -p admin -r http://ip:8081/repository/maven-snapshots/
二、一些问题
无法向私服上传jar包,可能是网络限制,或者是跨域。把jar包全部放和私服同一服务器中可正常上传。
标签:maven,http,repository,nexus,ip,私服,Maven,搭建 From: https://www.cnblogs.com/a999/p/16738912.html