上传新构建的jar包到服务器,很好用,记录
工具类:Upload.java
import com.jcraft.jsch.*;
import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.*;
/**
* @Description 扫描本地项目中新打的jar包,上传到服务器,清理日志,重启服务
* @Author Waria
* @Date 2020/7/1 15:55
*/
public class Upload {
public static Calendar cal = Calendar.getInstance();
//sftp通道
private static ChannelSftp sftp = null;
//sshSession链接
private static Session sshSession;
//本地工程路径
private static String localDir = "";
//过滤文件线程
public static ExecutorService executorService = Executors.newSingleThreadExecutor();
//是否清理日志
public static boolean clearLog = false;
//重启服务
public static boolean reStart_Enms_2 = true;
//需要上传的文件
public static ConcurrentMap<String, File> queueFiles = new ConcurrentHashMap();
/**
* 静态方法快:
* 读取配置文件,根据配置文件中设置的服务器等信息,打开连接
*/
static {
Properties properties = new Properties();
try {
//配置文件
properties.load(new FileInputStream("D:\\conf.properties"));
localDir = properties.getProperty("localDir");
//从日历的当前时间中减去多少小时
String subtractHour = properties.getProperty("subtractHour");
cal.add(Calendar.HOUR_OF_DAY, Integer.parseInt(subtractHour));
String port = properties.getProperty("prot");
//获取sshSession 账号-ip-端口
sshSession = new JSch().getSession(properties.getProperty("user"), properties.getProperty("host"),
Integer.parseInt(port));
//添加密码
sshSession.setPassword(properties.getProperty("password"));
Properties sshConfig = new Propertie