批量上传jar包到内网私服

声明:本文参考
https://blog.csdn.net/isea533/article/details/77197017
https://www.cnblogs.com/fengpingfan/p/5197608.html
https://www.cnblogs.com/yucy/p/7509561.html

【适用场景】:下载jar包、上传单个jar包、批量上传jar包到内网Maven 私服、发布自己的jar包到私服
【适用人群】:IT 懒人

一、下载jar包

下载单个jar包:http://mvnrepository.com/ 搜索下载 pom、jar、source、javadoc
下载多个jar包:配置一个新的本地仓库路径,在 settings.xml 中增加以下的配置(为了可以下载source和javadoc)

<server>
    <id>thirdpart</id>
    <username>admin</username>
    <password>admin123</password>
</server>

<profiles>  
  <profile>  
    <id>downloadSources</id>  
    <properties>  
      <downloadSources>true</downloadSources>  
      <downloadJavadocs>true</downloadJavadocs>             
    </properties>  
  </profile>  
</profiles>  

<activeProfiles>  
  <activeProfile>downloadSources</activeProfile>  
</activeProfiles>

二、上传命令

mvn deploy:deploy-file
-Durl=file:///home/me/m2-repo 
-DrepositoryId=some.repo.id 
-Dfile=./path/to/artifact-name-1.0.jar 
-DpomFile=./path/to/pom.xml 
-Dsources=./path/to/artifact-name-1.0-sources.jar 
-Djavadoc=./path/to/artifact-name-1.0-javadoc.jar

当执行命令有报错时,可以在命令的结尾加上"-X"进行调试

三、批量上传程序

import java.io.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Pattern;

/**
 * 上传依赖到 Maven 私服
 *
 * @author liuzenghui
 * @since 2017/7/31.
 */
public class Deploy {
   
    /**
     * mvn -s F:\.m2\settings.xml
     * org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file
     * -Durl=http://IP:PORT/nexus/content/repositories/thirdpart
     * -DrepositoryId=thirdpart
     * -Dfile=antlr-2.7.2.jar
     * -DpomFile=antlr-2.7.2.pom
     * -Dpackaging=jar
     * -DgeneratePom=false
     * -Dsources=./path/to/artifact-name-1.0-sources.jar
     * -Djavadoc=./path/to/artifact-name-1.0-javadoc.jar
     */
    public static final String BASE_CMD = "cmd /c mvn " +
            "-s F:\\.m2\\settings.xml " + 
            "deploy:deploy-file " +
            "-Durl=http://IP:PORT/nexus/content/repositories/thirdpart " +
            "-DrepositoryId=thirdpart " +
            "-DgeneratePom=false";

    public static final Pattern DATE_PATTERN = Pattern.compile("-[\\d]{8}\\.[\\d]{6}-");

    public static final Runtime CMD = Runtime.getRuntime();

    public static final Writer ERROR;

    public static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(10);

    static {
   
        Writer err = null;
        try {
   
            err = new OutputStreamWriter(new FileOutputStream("deploy-error.log"), "utf-8");
        } catch (Exception e) {
   
            e.printStackTrace();
            System.exit(0);
        }
        ERROR = err;
    }

    public static void main(String[] args) {
   
        deploy(new File("F:\\.m2\\repository").listFiles());
//        if(checkArgs(args)){
   
//            File file = new File(args[0]);
//            deploy(file.listFiles());
//        }
        EXECUTOR_SERVICE.shutdown();
        try {
   
            ERROR.close();
        } catch (IOException e) {
   
            e.printStackTrace();
        }
    }

    public static void error(String error){
   
        try {
   
            System.err.println(error);
            ERROR.write(error + "\n");
            ERROR.flush();
        } catch (IOException e) {
   
            e.printStackTrace();
        }
    }

    public static boolean 
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值