tomcat远程部署之java压缩解压

Shaka 5月前 ⋅ 349 阅读
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
help();
while (scanner.hasNext()) {
try {
String command = scanner.nextLine();
if (command.equals("help") || command.equals("?")) {
help();
} else if (command.equals("prod")) {
deploy("\\\\192.168.1.67\\dms");
System.exit(0);
} else if (command.equals("test")) {
deploy("\\\\192.168.1.30\\dms");
System.exit(0);
} else if (command.equals("quit") || command.equals("q")) {
log("已关闭");
scanner.close();
System.exit(0);
} else {
log("没有找到命令");
}
} catch (Exception e) {
e.printStackTrace();
log("请输入命令");
}
}
}

public static void deploy(String path) throws Exception {
log("正在压缩复制到" + path);
ClassLoader classLoader = DeployUtils.class.getClassLoader();
URL url = classLoader.getResource("");
if (url != null) {
File srcFile = new File(url.getFile());
srcFile = srcFile.getParentFile();

DateFormat df = new SimpleDateFormat("MMdd-HHmm");
File fileZip = new File(path + "/dms" + df.format(new Date()) + ".zip");
File fileDir = new File(srcFile.getPath() + "/dms");

Project project = new Project();
Zip zip = new Zip();
zip.setProject(project);
zip.setDestFile(fileZip);
FileSet fileSet = new FileSet();
fileSet.setProject(project);
fileSet.setDir(fileDir);
List<String> excludeList = new ArrayList<String>();
//不更新配置文件
excludeList.add("WEB-INF/classes/*.xml");
excludeList.add("WEB-INF/classes/*.properties");
//不更新jar包
excludeList.add("WEB-INF/lib");
excludeList.add("**/*.zip");
excludeList.add("**/*.jar");
//不更新资源包--注释后开启
excludeList.add("resources/css/**");
excludeList.add("resources/fonts/**");
excludeList.add("resources/img/**");
excludeList.add("resources/js/**");
excludeList.add("resources/pdf/**");
excludeList.add("resources/statics/**");
fileSet.appendExcludes(excludeList.toArray(new String[excludeList.size()]));
zip.addFileset(fileSet);
zip.execute();
log(fileZip + "打包发送完毕,正在解压");

Expand expand = new Expand();
expand.setProject(project);
expand.setSrc(fileZip);
expand.setDest(fileZip.getParentFile());
expand.setTaskName("unzip");
expand.execute();
log("解压完毕,请启动tomcat服务");
}
}

public static void help() {
log("****************欢迎使用****************");
log("help(?) 帮助说明");
log("quit(q) 退出程序");
log("请输入命令");
}

public static void log(String msg) {
System.out.println(msg);
}

注意:本文归作者所有,未经作者允许,不得转载

全部评论: 0

    我有话说: