此方法無論是jar包啟動(dòng)還是調(diào)試啟動(dòng)均可得到對應(yīng)路徑
ApplicationHome ah = new ApplicationHome(getClass());
// 獲取jar包所在目錄
String jarPath = ah.getSource().getParentFile().getAbsolutePath();
// 獲取jar包同級下的config.properties文件
File file = new File( + File.separator + "config.properties");
獲取resource(類)目錄下下的文件,無論是jar包啟動(dòng)還是調(diào)試啟動(dòng)均可獲得
ClassPathResource classPathResource = new ClassPathResource("static/image/logo.png");
File file = classPathResource.getFile();

1657240707545.png