mvn deploy命令:

mvn deploy:deploy-file -Dmaven.test.skip=true -Dfile=log-lib-1.1.jar -DgroupId=com.suncreate -DartifactId=log-lib -Dversion=1.1 -Dpackaging=jar -Durl=https://packages.aliyun.com/maven/repository/xxxxxxxxx -DrepositoryId=rdc-releases --settings D:\Java\maven-repository\settings.xml

mvn deploy:deploy-file -Dmaven.test.skip=true -Dfile=hadoop-common-3.1.1.jar -DgroupId=org.apache.hadoop -DartifactId=hadoop-common -Dversion=3.1.1 -Dclassifier=huawei  -Dpackaging=jar -Durl=https://packages.aliyun.com/maven/repository/xxxxxxxxx -DrepositoryId=rdc-releases --settings D:\Java\maven-repository\settings.xml

注意:-Dfile不是绝对路径

工具代码思路:遍历本地maven仓库文件夹中的.jar文件,通过正则表达式匹配获取jar包的groupId、artifactId、version、文件名等信息,通过调用cmd命令实现上传

工具是用C#写的,代码:

private void mavenUploads()
{
Task.Run(() =>
{
try
{
//string classifier = string.Empty;
string classifier = "huawei";
string[] files = Directory.GetFiles(@"D:\Java\maven-repository", "*" + classifier + ".jar", SearchOption.AllDirectories);
Log("文件总数:" + files.Length.ToString()); Regex regex = new Regex(@"^D:\\Java\\maven-repository\\([\\a-zA-Z0-9-]+)\\([a-zA-Z0-9-_\.]+)\\([0-9][a-zA-Z0-9-_\.]*)\\([a-zA-Z0-9-_\.]+" + classifier + @"\.jar)$", RegexOptions.IgnoreCase);
int count = 0;
foreach (string file in files)
{
Match m = regex.Match(file);
if (m.Success)
{
string dgroupId = m.Groups[1].Value.Replace("\\", ".");
string dartifactId = m.Groups[2].Value;
string dversion = m.Groups[3].Value;
string fileName = m.Groups[4].Value; string tempFileName = fileName; if (fileName.Contains("-sources.jar"))
{
continue;
}
if (fileName.Contains("-javadoc.jar"))
{
continue;
}
if (!string.IsNullOrWhiteSpace(classifier))
{
tempFileName = @"D:\temp\" + fileName.Replace("-" + classifier + ".jar", ".jar");
} if (!File.Exists(tempFileName))
{
File.Copy(file, tempFileName, true);
bool result = mavenUpload(tempFileName, dgroupId, dartifactId, dversion, classifier);
if (result)
{
count++;
Log("已成功上传,count=" + count + ",文件名:" + tempFileName);
}
else
{
count++;
Log("上传失败,count=" + count + ",文件名:" + tempFileName);
}
}
else
{
count++;
Log("无需重复上传,count=" + count + ",文件名:" + file);
}
}
else
{
count++;
Log("不匹配已跳过,count=" + count + ",文件名:" + file);
}
} Log("完成");
}
catch (Exception ex)
{
Log("出错:" + ex.Message + "\r\n" + ex.StackTrace);
}
});
} private bool mavenUpload(string dfile, string dgroupId, string dartifactId, string dversion, string dclassifier)
{
if (!string.IsNullOrWhiteSpace(dclassifier))
{
dclassifier = "-Dclassifier=" + dclassifier;
}
else
{
dclassifier = string.Empty;
} string cmdStr = string.Format(@"
mvn deploy:deploy-file
-Dmaven.test.skip=true
-Dfile={0}
-DgroupId={1}
-DartifactId={2}
-Dversion={3}
{4}
-Dpackaging=jar
-Durl=https://packages.aliyun.com/maven/repository/xxxxxxxxx
-DrepositoryId=rdc-releases
--settings D:\Java\maven-repository\settings.xml",
dfile, dgroupId, dartifactId, dversion, dclassifier); cmdStr = cmdStr.Replace("\r\n", "");
bool result = runCmd(cmdStr);
return result;
} private bool runCmd(string cmdStr)
{
Process p = new Process();
//设置要启动的应用程序
p.StartInfo.FileName = "cmd.exe";
//是否使用操作系统shell启动
p.StartInfo.UseShellExecute = false;
//接受来自调用程序的输入信息
p.StartInfo.RedirectStandardInput = true;
//输出信息
p.StartInfo.RedirectStandardOutput = true;
//输出错误
p.StartInfo.RedirectStandardError = true;
//不显示程序窗口
p.StartInfo.CreateNoWindow = true;
//启动程序
p.Start(); //向cmd窗口发送输入信息
p.StandardInput.WriteLine(cmdStr);
p.StandardInput.WriteLine("exit"); p.StandardInput.AutoFlush = true; //获取输出信息
string strOuput = p.StandardOutput.ReadToEnd(); //等待程序执行完退出进程
p.WaitForExit();
p.Close(); if (strOuput.Contains("ERROR"))
{
Log(strOuput);
return false;
}
else
{
return true;
}
}

批量上传 jar 包到远程 maven 仓库的更多相关文章

  1. Maven使用deploy上传jar包到远程库

    一.环境准备 首先需要在本地环境安装好maven,并且在环境变量配置好 二.配置远程库认证 需要在./conf/setting.xml(maven的配置文件,不要弄错)中配置需要远程上传库的地址,用户 ...

  2. [转] 手动上传jar包到远程仓库 (maven deploy)

    [From] https://my.oschina.net/360yg/blog/1588899 前言:通常允许上传的远程仓库有两种:Snapshots和Releases,分别为快照版仓库和稳定版仓库 ...

  3. Maven使用deploy上传jar包到远程库 以Oracle驱动为例

    一.首先要得到Oracle JDBC Driver 1.通过Oracle官方网站下载相应版本:http://www.oracle.com/technetwork/database/features/j ...

  4. 部署Jar包到远程Maven仓库

    在使用maven开发工程时,模块A可能会依赖模块B的jar包,如果两个模块都是在一个工程里,只需要在模块A的pom文件中加入模块B的依赖信息,模块A就可以加载模块B的jar包.但如果模块A与模块B在不 ...

  5. maven安装 maven上传jar包到库里面

    maven的安装与配置:http://pansanday.blog.163.com/blog/static/381662802012727103454743/ maven上传jar包到库里面: 将私有 ...

  6. Maven第四篇【私有仓库、上传jar包、引用私服jar包、上传本地项目到私服】

    搭建私有服务器 前面已经说过了,我们使用Maven的使用,如果需要导入相对应的jar包,Maven首先会在我们的本地仓库中寻找->私有仓库->中心仓库- 然而,我们的本地仓库常常没有想要的 ...

  7. 【Maven】2.使用Nexus3搭建Maven私服+上传第三方jar包到本地maven仓库

    参考文章: http://www.cnblogs.com/luotaoyeah/p/3791966.html --------------------------------------------- ...

  8. 实测Maven上传jar包到私服的方法归纳

    Hello,各位小伙伴大家好,我是小栈君.好久不见,最近因为工作的缘故,导致了更新变慢,但是小栈君也在积极的做素材的规划,毕竟学习知识点的归纳和提炼需要一定的时间. 所以还请大家多多见谅,下一期的分享 ...

  9. 使用Nexus3搭建Maven私服+上传第三方jar包到本地maven仓库

    1.搭建Maven私服背景 公司还是按捺不住,要搭建一个自己的Maven本地仓库,可以让开发人员down架包,从内网还是快很多. 这样公司的maven本地仓库就是 开发人员自己电脑上的maven仓库 ...

  10. gradle上传jar包到maven公共仓库

    首先这里说的中央仓库 是指的 https://issues.sonatype.org/ 而不是maven私服. 其次是使用gradle上传jar包,maven上传,网上有很多教程,这里不做赘述. 首选 ...

随机推荐

  1. 4. Shell 循环语句

    重点: 条件测试. read. Shell 环境配置. case. for. find. xargs. gzip,bzip2,xz. tar. sed. 1)循环 1.1)循环执行介绍 将某代码段重复 ...

  2. 通信技术 Communication

    缩写 全称 翻译 备注 I2C Inter-Integrated Circuit 集成电路总线 通信协议 SPI Serial Peripheral Interface 串行外设接口 通信协议 QSP ...

  3. python3使用pandas备份mysql数据表

    操作系统 :CentOS 7.6_x64 Python版本:3.9.12 MySQL版本:5.7.38 日常开发过程中,会遇到mysql数据表的备份需求,需要针对单独的数据表进行备份并定时清理数据. ...

  4. raft算法的自我理解

    1.raft算法是什么? 答:共识算法 2.raft算法有什么用? 答:维持不同机器的强一致性 3.raft算法通过什么方式来维持不同机器的强一致性? 答:传递log日志 ,按照官方的说法日志里面包含 ...

  5. [python][图像切割]给定手写数字图片完成数字切割

    import torch import torch.nn as nn from torchvision import transforms from PIL import Image, ImageOp ...

  6. 关于yolov3在训练自己数据集时容易出现的bug集合,以及解决方法

    早先写了一篇关于yolov3训练自己数据集的博文Pytorch实现YOLOv3训练自己的数据集 其中很详细的介绍了如何的训练自定义的数据集合,同时呢笔者也将一些容易出现的bug写在了博文中,想着的是可 ...

  7. 自定义线程池将异常"吃了"

    今天在做项目时,写了一个使用自定义线程池执行远程调用 // 删除购物车信息 corePoolExecutor.submit(() -> { try { cartFeignClient.delet ...

  8. 基于一维卷积神经网络模型的AI量化智能选股策略

    这是早前BigQuant专题研究:基于卷积神经网络CNN的深度学习因子选股模型.卷积神经网络(Convolutional Neural Network, CNN),是计算机视觉研究和应用领域中最具影响 ...

  9. Python——第二章:字符的编码encode和解码decode

    相关阅读:字符集(Character Set)和编码(Encoding)的历史演化 字符集和编码的总结: 1. ASCII编码: 8bit, 1byte => 256(最大可表示)2. GBK编 ...

  10. DVWA Cross Site Scripting (XSS) 跨站脚本攻击

    文章目录 DVWA_XSS(Stored) 存储性XSS 1.Low 2.Medium 3.High 4.Impossible XSS平台 DVWA_XSS(Stored) 存储性XSS 一句话概括: ...