This commit is contained in:
2026-07-08 22:11:53 +08:00
parent 6cc4deb4eb
commit 59de38c87b

View File

@@ -1,7 +1,43 @@
package top.gtb520.java.util; package top.gtb520.java.util;
import java.util.Arrays;
public class main { public class main {
static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello, World!");
// 获取当前运行的JAR文件路径
String path = main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
if (System.getProperty("os.name").startsWith("Windows")) {
path = path.replace('/', '\\');
//去除路径最前面的 “\”
path = path.substring(1);
}
// System.out.println("JAR文件路径" + path);
if (args == null || args.length == 0) {
System.out.println("参数为空使用方法java -jar " + path + " -run");
System.exit(0);
} else {
System.out.println("开始执行");
if (args[0].equals("-run")) {
// 变量String 为传入的第1号命令参数
System.out.println("传入的参数为:" + Arrays.toString(args));
System.out.println("参数0号: " + args[0]);
System.out.println("参数1号: " + args[1]);
// 判断系统是否为WindowsAmd64或LinuxAmd64
if (System.getProperty("os.name").toLowerCase().contains("win") && System.getProperty("os.arch").toLowerCase().contains("amd64")) {
System.out.println("系统为 Windows x64");
} else if (System.getProperty("os.name").toLowerCase().contains("linux") && System.getProperty("os.arch").toLowerCase().contains("amd64")) {
System.out.println("系统为 Linux x64");
} else {
System.out.println("系统不支持,程序退出");
}
}
}
} }
} }