当你部署了一台nexus3服务器 想从本地仓库上传Jar包,如果你嫌一个一个上传太慢 你可以试试这个方法
import os
# 两个路径为你的本地仓库的路径 相同即可
CALCPATH = r"C:\xxxxxxx\.m2\repository"
ROOTPATH = r"C:\xxxxxxx\.m2\repository"
# 仓库名称
repoId = 'maven-releases'
# 仓库url
repoUrl = 'http://xxxxxxxxx/repository/maven-releases/'
def getAllJar():
for root, dir, files in os.walk(ROOTPATH):
for each in files:
if each.endswith('jar'):
info = getInfo(root, each)
info['filepath'] = root+'\\'+each
uploadJar(info)
def uploadJar(info):
filepath = info['filepath']
jarGroupid = info['groupId']
jarArtifactid = info['artifactId']
jarVersion = info['version']
jarShell = 'mvn deploy:deploy-file' + ' -DrepositoryId=' + repoId + ' -Durl=' + repoUrl + ' -Dfile=' + filepath + ' -DgroupId=' + jarGroupid + ' -DartifactId=' + jarArtifactid + ' -Dversion=' + jarVersion + ' -Dpackgaing=jar'
print(jarShell)
os.system(jarShell)
def getInfo(root, each):
res = {}
t = root[len(CALCPATH) + 1:].rsplit('\\', 1)
res['groupId'] = t[0].replace('\\', '.')
res['version'] = t[1]
res['artifactId'] = each.rsplit('-', 1)[0]
return res
if __name__ == "__main__":
print("开始执行")
getAllJar()