package com.vci.web.maven;
|
|
import java.io.*;
|
|
/**
|
* 批量上传文件到maven私服
|
* @author weidy
|
* @date 2021/6/2
|
*/
|
public class BatchRedeployJar2Maven {
|
|
public static final String MAVEN_PATH = "C:\\developer\\apache-maven-3.8.1\\bin";
|
|
public static final String JAR_CLIENT_PATH = "C:\\developer\\platform2020\\platform-runtime-2022\\libs\\modules\\client";
|
|
public static final String JAR_COMMON_PATH = "C:\\developer\\platform2020\\platform-runtime-2022\\libs\\modules\\common";
|
|
public static final String JAR_SERVER_PATH = "C:\\developer\\platform2020\\platform-runtime-2022\\libs\\modules\\server";
|
|
public static final String JAR_BASE_PATH = "C:\\developer\\platform2020\\platform-runtime-2022\\libs\\base";
|
|
public static final String SETTINGS = "${user.home}\\.m2";
|
|
public static final String GROUP_ID = "com.vci.platform";
|
|
public static final String VERSION = "2022.RELEASE";
|
|
public static final String URL = "http://nexus.vci-tech.com:9000/repository/maven-releases";
|
public static void main(String[] args) {
|
|
/**
|
* 使用之前请先安装maven,或者直接使用idea的插件
|
* 然后修改上方的jar_xxx_path,如果有增加路径可以自行添加
|
*/
|
BatchRedeployJar2Maven redeploy = new BatchRedeployJar2Maven();
|
redeploy.redeploy(JAR_CLIENT_PATH);
|
redeploy.redeploy(JAR_COMMON_PATH);
|
redeploy.redeploy(JAR_SERVER_PATH);
|
redeploy.redeploy(JAR_BASE_PATH);
|
}
|
|
public void redeploy(String path){
|
File folder = new File(path);
|
if(folder.exists()) {
|
File[] files = folder.listFiles();
|
if (files != null) {
|
System.out.println("扫描文件夹" + path);
|
for (File jarFile : files) {
|
String name = jarFile.getName();
|
String nameNotExtension = name;
|
if (name.contains(".")) {
|
nameNotExtension = name.substring(0, name.lastIndexOf("."));
|
}
|
String cmd = "mvn deploy:deploy-file \"-DgroupId=" + GROUP_ID +
|
"\" \"-DartifactId=" + nameNotExtension + "\" \"-Dversion=" + VERSION + "\" \"-Dpackaging=jar\" \"-Durl=" + URL + "\" \"-Dfile=" + jarFile.getAbsolutePath() + "\" \"-DrepositoryId=rdc-releases\"";
|
|
Process proc = null;
|
try {
|
proc = Runtime.getRuntime().exec(new String[]{"cmd", "/C", cmd}, null, new File(MAVEN_PATH));
|
printMessage(proc.getInputStream());
|
printMessage(proc.getErrorStream());
|
proc.waitFor();
|
} catch (IOException | InterruptedException e) {
|
e.printStackTrace();
|
} finally {
|
if (proc != null) {
|
proc.destroy();
|
}
|
}
|
System.out.println("完成" + name);
|
}
|
System.out.println("完成扫描文件夹" + path);
|
}
|
}
|
|
}
|
|
private static void printMessage( final InputStream input) {
|
new Thread(new Runnable() {
|
public void run() {
|
Reader reader =null;
|
BufferedReader bf=null;
|
String line = null;
|
try {
|
reader= new InputStreamReader(input);
|
bf = new BufferedReader(reader);
|
while((line=bf.readLine())!=null) {
|
System.out.println(line);
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}finally {
|
try {
|
if (reader != null) {
|
reader.close();
|
}
|
if (bf != null) {
|
bf.close();
|
}
|
}catch (Throwable e){
|
|
}
|
}
|
}
|
}).start();
|
}
|
}
|