当前位置:网站首页>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 .
边栏推荐
- ICML 2022 || 3DLinker: 用于分子链接设计的E(3)等变变分自编码器
- The initial arrangement of particles in SPH (solved by two pictures)
- debug和release的区别
- [sword finger offer] questions 1-5
- 企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
- Summary of wechat applet display style knowledge points
- OSEK标准ISO_17356汇总介绍
- 【二叉树】节点与其祖先之间的最大差值
- The Chinese output of servlet server and client is garbled
- [JS] - [sort related] - Notes
猜你喜欢
colResizable. JS auto adjust table width plug-in
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
Qt加法计算器(简单案例)
heatmap. JS picture hotspot heat map plug-in
Intelligence test to see idioms guess ancient poems wechat applet source code
MariaDB's Galera cluster application scenario -- multi master and multi active databases
Selected cutting-edge technical articles of Bi Ren Academy of science and technology
Jar批量管理小工具
Solution record of jamming when using CAD to move bricks in high configuration notebook
The small program vant tab component solves the problem of too much text and incomplete display
随机推荐
Mysql database backup and recovery -- mysqldump command
cout/cerr/clog的区别
【ODX Studio编辑PDX】-0.2-如何对比Compare两个PDX/ODX文件
Wechat official account solves the cache problem of entering from the customized menu
[odx Studio Edit pdx] - 0.2 - Comment comparer deux fichiers pdx / odx
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
如何报考PMP项目管理认证考试?
How long does it take to obtain a PMP certificate?
Solution record of jamming when using CAD to move bricks in high configuration notebook
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
【ODX Studio编辑PDX】-0.3-如何删除/修改Variant变体中继承的(Inherited)元素
Editplus-- usage -- shortcut key / configuration / background color / font size
How to choose a securities company? Is it safe to open an account on your mobile phone
蓝天NH55系列笔记本内存读写速度奇慢解决过程记录
PICT 生成正交测试用例教程
P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列
[graph theory] topological sorting
How to apply for PMP project management certification examination?
PaddleOCR教程
Application of machine learning in housing price prediction