获取lib同级文件路径

获取lib同级文件路径


  • 话不多说直接上代码

java.net.URL url = MyBatisGenerator.class.getProtectionDomain().getCodeSource().getLocation();
String filePath = null;
try {
filePath = java.net.URLDecoder.decode(url.getPath(), "utf-8");
// System.out.println("filePath1:"+filePath);
} catch (Exception e) {
e.printStackTrace();
}
if (filePath.endsWith(".jar"))
filePath = filePath.substring(0, filePath.lastIndexOf("/") + 1);
java.io.File file_temp = new java.io.File(filePath);
filePath = file_temp.getAbsolutePath();
// System.out.println("filePath2:"+filePath);
File configFile=new File(filePath+"\\generatorConfig.xml");

你可能感兴趣的:(java)