当前位置:网站首页>Jar batch management gadget
Jar batch management gadget
2022-07-04 23:23:00 【lijiamin-】
List of articles
Preface
One Jar Package management gadget , At present, it has the following functions , Later, it can be expanded slowly
1. Search all under the current project path jar And copy to a certain path
2. Execute jar Package batch run start
3.Kill all java process
One 、 The code structure
These functions can be extended slowly by themselves , At present, I have only done what I need , First, let's look at file processing
JarManagerApplication
package com.ljm;
import com.ljm.play.One;
import com.ljm.play.Two;
import java.io.IOException;
import java.util.Scanner;
/** * One JAR Manage small scripts * 1. Search all under the current project path jar And copy to a certain path * 2. Execute jar Package batch run start * 3.kill all java process * @author Li Jiamin */
public class JarManagerApplication {
public static void main(String[] args) {
menu();
String InputStr = null;
// Create a scanner object For receiving keyboard data
Scanner scannerShow = new Scanner(System.in);
while (!scannerShow.hasNext() == true) {
// Waiting for user input
}
InputStr = scannerShow.next();
System.out.println(" The function item you entered is :" + InputStr);
switch (InputStr) {
case "1":
// 1. Search all under the current project path jar And copy to a certain path
One.selectMethod();
One.copyMethod();
break;
case "2":
// 2. Execute jar Package batch run start
Two.runJar();
break;
case "3":
// 3.kill all java process
break;
default:
System.out.println("=== Parameter error ===");
break;
}
// Program exit
System.exit(0);
}
/** * One JAR Manage small scripts * 1. Search all under the current project path jar And copy to a certain path * 2. Execute jar Package batch run start * 3.kill all java process */
public static void menu() {
System.out.println(" One JAR Manage small scripts -----");
System.out.println(" Please enter the function item ( Numbers ):");
System.out.println("1. Search all under the current project path jar And copy to a certain path ");
System.out.println("2. Execute jar Package batch run start ");
System.out.println("3.kill all java process ");
System.out.println();
}
}
One
package com.ljm.play;
import com.ljm.handle.FileHandler;
import java.io.IOException;
import java.util.List;
import java.util.Scanner;
public class One {
/** * Query search */
public static void selectMethod() {
// E:\44_JAVA_Protect\ Hangzhou metro \hangzhou-metro-server-new
String pathInputStr = "";
// Create a scanner object For receiving keyboard data
Scanner scanner = new Scanner(System.in);
System.out.println(" Please enter the project path :");
// Determine whether the user has input string
if (scanner.hasNext() == true) {
pathInputStr = scanner.next();
System.out.println(" The path you entered is :" + pathInputStr);
}
// Search for
FileHandler.getBladeJar(pathInputStr);
}
/** * Copy to a path */
public static void copyMethod() {
// Directory location
String pathInputStr = "";
// Create a scanner object For receiving keyboard data
Scanner scanner = new Scanner(System.in);
System.out.println(" Please enter the path to copy :");
// Determine whether the user has input string
if (scanner.hasNext() == true) {
pathInputStr = scanner.next();
System.out.println(" The path you entered is :" + pathInputStr);
}
List<String> bladeJarPathList = FileHandler.getBladeJarPathList();
List<String> bladeJarNameList = FileHandler.getBladeJarNameList();
System.out.println(" Start copying .......");
for (int i = 0; i < bladeJarPathList.size(); i++) {
String sPath = bladeJarPathList.get(i);
String sName = pathInputStr + "\\" + bladeJarNameList.get(i);
try {
FileHandler.copy(sPath, sName);
System.out.println(" Copied file :" + (i + 1) + " Total quantity :" + bladeJarPathList.size());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
FileHandler
package com.ljm.handle;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/** * File processor * @author Li Jiamin */
public class FileHandler {
private static List<String> jarPathList = new ArrayList<>();
private static List<String> jarNameList = new ArrayList<>();
/** JAR Package path */
public static List<String> getBladeJarPathList() {
return jarPathList;
}
/** JAR Package name */
public static List<String> getBladeJarNameList() {
return jarNameList;
}
/** * Find all BLADE-JAR Postfix file * @param path */
public static void getBladeJar(String path) {
File file = new File(path);
if (file.exists()) {
File[] files = file.listFiles();
if (null != files) {
for (File file2 : files) {
if (file2.isDirectory()) {
getBladeJar(file2.getAbsolutePath());
} else {
String file2AbsolutePath = file2.getAbsolutePath();
int length = file2AbsolutePath.length();
int lastIndexOf = file2AbsolutePath.lastIndexOf(".");
if (lastIndexOf <= 0) {
continue;
}
if (file2AbsolutePath.substring(lastIndexOf, length).equals(".jar")) {
if (!file2AbsolutePath.contains("common") && !file2AbsolutePath.contains("api") && !file2AbsolutePath.contains("lib")) {
jarPathList.add(file2AbsolutePath);
jarNameList.add(file2.getName());
}
}
}
}
}
}
}
/** * from srcPathName Copy the contents of the file to destPathName In file * @param srcPathName Input file * @param destPathName The output file * @throws IOException */
public static void copy(String srcPathName, String destPathName) throws IOException {
// establish IO flow
// FileInputStream and FileOutputStream
FileInputStream fis = new FileInputStream(srcPathName);
FileOutputStream fos = new FileOutputStream(destPathName);
// from fis Read data in stream , writes fos Streaming
byte[] data = new byte[10];
int len;
while ((len = fis.read(data)) != -1) {
fos.write(data, 0, len);
}
// close
fis.close();
fos.close();
}
}
The above code summarizes several function points
- Search for files with a suffix under a certain path
- Copy file
- IO flow
Then look at the code started by the batch execution script
package com.ljm.play;
import com.ljm.handle.FileHandler;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Two {
/** * Run all Jar */
public static void runJar() {
String pathInputStr = "";
// Create a scanner object For receiving keyboard data
Scanner scanner = new Scanner(System.in);
System.out.println(" Please enter JAR route :");
// Determine whether the user has input string
if (scanner.hasNext() == true) {
pathInputStr = scanner.next();
System.out.println(" The path you entered is :" + pathInputStr);
}
// Search for
FileHandler.getBladeJar(pathInputStr);
List<String> jarPathList = FileHandler.getBladeJarPathList();
// cmd
try {
FileWriter fileWriter = new FileWriter(pathInputStr + "\\" + "start.bat");
fileWriter.append("@echo off \n");
fileWriter.append("\n");
for (String strP : jarPathList) {
fileWriter.append("start java -d64 -server -Xms512m -Xmx2048m -jar " + strP + "\n");
fileWriter.append("choice /t 10 /d y /n > null " + "\n");
fileWriter.append("\n");
}
fileWriter.flush();
fileWriter.close();
Process p = Runtime.getRuntime().exec("cmd /c " + pathInputStr + "\\" + "start.bat");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
It's delicious , The disadvantage is that the path should be in English , This has not been solved , A bit late .
Two 、 Open source warehouse address
Address |
---|
The official is still reviewing , undetermined |
summary
Tips : Here is a summary of the article :
for example : That's what we're going to talk about today .
边栏推荐
- Summary of wechat applet display style knowledge points
- How long does it take to obtain a PMP certificate?
- 微软禁用IE浏览器后,打开IE浏览器闪退解决办法
- OSEK标准ISO_17356汇总介绍
- 可观测|时序数据降采样在Prometheus实践复盘
- ffmpeg快速剪辑
- LabVIEW中比较两个VI
- The difference between debug and release
- [odx Studio Edit pdx] - 0.2 - Comment comparer deux fichiers pdx / odx
- Solution record of jamming when using CAD to move bricks in high configuration notebook
猜你喜欢
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
45岁教授,她投出2个超级独角兽
MariaDB's Galera cluster application scenario -- multi master and multi active databases
字体设计符号组合多功能微信小程序源码
法国学者:最优传输理论下对抗攻击可解释性探讨
Redis: redis transactions
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
Redis getting started complete tutorial: Key Management
The initial trial is the cross device model upgrade version of Ruijie switch (taking rg-s2952g-e as an example)
uniapp 除了数字,其他输入无效
随机推荐
A mining of edu certificate station
The Chinese output of servlet server and client is garbled
Redis:Redis的事务
LabVIEW中比较两个VI
解决无法通过ssh服务远程连接虚拟机
A complete tutorial for getting started with redis: redis usage scenarios
heatmap. JS picture hotspot heat map plug-in
刷题指南-public
Font design symbol combination multifunctional wechat applet source code
Principle of lazy loading of pictures
phpcms付费阅读功能支付宝支付
PICT 生成正交测试用例教程
Solve the problem that the virtual machine cannot be remotely connected through SSH service
ECCV 2022 | Tencent Youtu proposed disco: the effect of saving small models in self supervised learning
Network namespace
香港珠宝大亨,22亿“抄底”佐丹奴
Photoshop批量给不同的图片添加不同的编号
初试为锐捷交换机跨设备型号升级版本(以RG-S2952G-E为例)
Docker镜像的缓存特性和Dockerfile
【js】-【排序-相关】-笔记