赞
踩
(1)由于公司的研发环境迁移到N网的不能联网,不过本地仓库已经有很多的 maven 的 jar 包了,便想将其从本地仓库导入到N网 Nexus 私服中。
(2)Nexus2.x 批量导入本地库是十分容易的,只需将库文件夹复制到对应 nexus 库下面,去网页刷新一下索引就OK了。在 Nexus3.x 中,我们可以很方便的使用 shell 脚本进行批量导入jar包。
地址:https://help.sonatype.com/repomanager3/product-information/download
tar -zxvf nexus-3.25.1-04-unix.tar.gz
部署环境上一般要求五位端口号,这里把默认端口(8081)改为28081
# 进入etc文件夹
cd /opt/nexus-3.25.1-04/etc
# 修改配置
vi nexus-default.properties
# 更改端口号 port
application-port=28081
# 进入bin目录
cd /opt/nexus-3.25.1-04/bin
# 可自行调整配置 nexus.vmoptions
vi nexus.vmoptions
必须有JDK环境,该节点已经部署过JDK8环境,此处略过安装JDKJ的步骤;
# 启动命令 &为后台启动:
./nexus run & 也可以改为./nexus start &
http://ip+端口,或者http://ip+端口/nexus3 进入nexus3的管理页面
首次访问页面,点击右上角 Sign In,会提示初始admin的密码文件路径
cat /opt/sonatype-work/nexus3/admin.password
创建maven仓库,用存放本地已经下好的jar包



将个人PC端本地已经下载好的jar包并上传到Linux服务器上
# 将仓库打包文件上传到服务上并解压
unzip repository.zip
vi 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 './mavenUpload\.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}/{} ;

# 脚本授权
chmod +x mavenimport.sh
# 执行脚本
./mavenimport.sh -u admin -p Admin123 -r http://172.16.24.163:28081/repository/repository/

修改 apache-maven-3.6.1/conf /settings.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:/Program Files/repository</localRepository> <servers> <!-- server 配置私服账号,允许匿名访问忽略了此处 <server> <id>nexus3-mave</id> <username>admin</username> <password>Admin123</password> </server> --> </servers> <mirrors> <!-- 增加maven私服地址 --> <mirror> <id>nexus3-mave</id> <mirrorOf>nexus3-mave</mirrorOf> <url>http://172.16.24.163:28081/repository/repository//</url> </mirror> <!-- 以下是公网maven仓库地址,N网无法使用,暂且保留 --> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>central</id> <name>Maven Repository Switchboard</name> <url>http://repo1.maven.org/maven2/</url> <mirrorOf>central</mirrorOf></mirror> <mirror> <id>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo2.maven.org/maven2/</url> </mirror> <mirror> <id>ibiblio</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> </mirror> <!-- 中央仓库在中国的镜像 --> <mirror> <id>maven.net.cn</id> <name>oneof the central mirrors in china</name> <url>http://maven.net.cn/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> </settings>
"Missing artifact......"的解决办法在使用Maven开发时,会碰到一些问题,例如“Missing artifact xxx.xxx.jar",而通过下面的方式进行解决。
1、确认本地repository相应目录中是否下载好了对应的包,检查文件大小,尝试删除重新下载;
2、检查maven私服是否有对应的jar,不存在还需上传到私服。(N网开发就这点不方便)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。