当前位置:网站首页>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 .
边栏推荐
- The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
- 香港珠宝大亨,22亿“抄底”佐丹奴
- [JS] - [dynamic planning] - Notes
- 初试为锐捷交换机跨设备型号升级版本(以RG-S2952G-E为例)
- 机器学习在房屋价格预测上的应用
- [crawler] jsonpath for data extraction
- 刷题指南-public
- Notepad++--编辑的技巧
- OSEK standard ISO_ 17356 summary introduction
- Combien de temps faut - il pour obtenir un certificat PMP?
猜你喜欢
随机推荐
ScriptableObject
香港珠宝大亨,22亿“抄底”佐丹奴
[crawler] jsonpath for data extraction
Etcd database source code analysis - brief process of processing entry records
How long does it take to obtain a PMP certificate?
[Jianzhi offer] 6-10 questions
解决无法通过ssh服务远程连接虚拟机
The difference between cout/cerr/clog
After Microsoft disables the IE browser, open the IE browser to flash back the solution
取得PMP證書需要多長時間?
The difference between debug and release
字体设计符号组合多功能微信小程序源码
实战模拟│JWT 登录认证
Header file duplicate definition problem solving "c1014 error“
法国学者:最优传输理论下对抗攻击可解释性探讨
Notepad++ -- editing skills
Servlet+JDBC+MySQL简单web练习
MariaDB的Galera集群-双主双活安装设置
The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
Question brushing guide public