maven 使用shell命令 批量上傳jar包到遠程maven庫 python 代碼

背景:

需要批量導入jar包到遠程庫,有遠程庫的網頁登陸名和密碼(admin權限),準備寫程序批量導入。

 

1、前提條件

1、本地安裝好了maven

2、有程序的運行環境(我用的python編寫的)

 

2、核心代碼:

 

核心代碼:

#獲取根路徑的所有jar包
def getAllJar(rootpath):
   lists=[]
for root ,dir,files in os.walk(rootpath):
for each in files:
if each.endswith('jar'):
          lists.append(each)
  return lists

#傳入一個根路徑以及一個目標jar包路徑,可以返回一個jar上傳的shell語句
#rootpath='D:\jarpathdir'
#filepath='D:\jarpathdir\org\apache\logging\..\*.jar'
def getShell(rootpath,filepath):
delRootFilePath=filepath.repace(rootpath,'')[1:]

repoId='myrepo'
repoUrl='http://.../repository/myrepo'

templist=delRootFilePath.split('\\')
jarVersion=templist[-2]
jarArtifactid=templist[-3]
jarGroupid='.'.join(templist[:-3])

jarShell='mvn deploy:deploy-file'\
+'-DrepositoryId='+repoId\
+'-Durl='+repoUrl\
+'-Dfile='+filepath\
+'-Dgroupid='+jarGroupid\
+'-DartifactId='+jarArtifactid\
+'-Dversion'+jarVersion\
+'-Dpackgaing=jar'
return jarShell


#執行shell的方法:
os.system(jarshell)

  執行此語句就可以上傳一個jar包到遠程庫,多個語句依次執行,就可以批量上傳了。


 

流程:

1) 設置maven的conf文件夾中的setting文件,把用戶名密碼寫進去,並註釋掉所有遠程鏡像庫

2)把responsary庫拷貝到其他位置(否則上傳不成功),並以此作爲代碼中的rootpath

3)結合以上代碼原理,構建每一個jar的shell語句依次執行

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章