zoukankan      html  css  js  c++  java
  • 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:jarpathdirorgapachelogging..*.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语句依次执行

  • 相关阅读:
    数据库设计范式
    SQL 触发器
    SQL查询上月和本月两个月的语句
    angularjs学习总结 详细教程
    指令
    重复 HTML 元素
    AngularJS 数据绑定
    AngularJS 指令.
    AngularJS 数组
    AngularJS 对象
  • 原文地址:https://www.cnblogs.com/51python/p/14053089.html
Copyright © 2011-2022 走看看