diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF index 04d8090..384f1c6 100644 --- a/src/META-INF/MANIFEST.MF +++ b/src/META-INF/MANIFEST.MF @@ -1,4 +1,4 @@ Manifest-Version: 1.0 Main-Class: cn.erning.aabinstaller.Main -Implementation-Version: 1.2.1 +Implementation-Version: 1.2.2 diff --git a/src/cn/erning/aabinstaller/util/FileUtil.java b/src/cn/erning/aabinstaller/util/FileUtil.java index 6eecd34..1ffdf52 100644 --- a/src/cn/erning/aabinstaller/util/FileUtil.java +++ b/src/cn/erning/aabinstaller/util/FileUtil.java @@ -21,4 +21,21 @@ public static void delete(File file){ file.delete(); } } + + public static String getSelfPath(){ + // 方法一:获取当前可执行jar包所在目录 + String filePath = System.getProperty("java.class.path"); + //得到当前操作系统的分隔符,windows下是";",linux下是":" + String pathSplit = System.getProperty("path.separator"); + //若没有其他依赖,则filePath的结果应当是该可运行jar包的绝对路径,此时我们只需要经过字符串解析,便可得到jar所在目录 + if(filePath.contains(pathSplit)){ + filePath = filePath.substring(0,filePath.indexOf(pathSplit)); + }else if (filePath.endsWith(".jar")) { + + //截取路径中的jar包名,可执行jar包运行的结果里包含".jar" + filePath = filePath.substring(0, filePath.lastIndexOf(File.separator) + 1); + } + System.out.println("jar包所在目录:"+filePath); + return filePath; + } } diff --git a/src/cn/erning/aabinstaller/util/Installer.java b/src/cn/erning/aabinstaller/util/Installer.java index 1c2be7e..5e7b701 100644 --- a/src/cn/erning/aabinstaller/util/Installer.java +++ b/src/cn/erning/aabinstaller/util/Installer.java @@ -327,9 +327,9 @@ private static Device[] parsingDevices(String content){ private static String getAdbPath(){ String adbPath; if(System.getProperties().getProperty("os.name").toLowerCase().startsWith("windows")){ - adbPath = new File("").getAbsolutePath()+"\\adb.exe"; + adbPath = new File(FileUtil.getSelfPath()).getAbsolutePath()+"\\adb.exe"; }else{ - adbPath = new File("").getAbsolutePath()+"/adb"; + adbPath = new File(FileUtil.getSelfPath()).getAbsolutePath()+"/adb"; } boolean hasAdb = new File(adbPath).exists(); System.out.println("ADB文件路径:"+adbPath); @@ -338,4 +338,6 @@ private static String getAdbPath(){ } return hasAdb ? adbPath : null; } + + }