SpringBoot项目如何获取jar包运行所在的目录呢?
下文笔者讲述SpringBoot项目中jar包运行路径的查看方法分享,如下所示
查看jar包运行路径
//方式1
File path = new File(ResourceUtils.getURL("classpath:").getPath());
if(!path.exists()) path = new File("");
System.out.println(path.getAbsolutePath());
//方式2
System.out.println(System.getProperty("user.dir"));
//方式3
String path1 = ClassUtils.getDefaultClassLoader().getResource("").getPath();
System.out.println(URLDecoder.decode(path1, "utf-8"));
//方式4
String path2 = ResourceUtils.getURL("classpath:").getPath();
System.out.println(path2);
//方式5
ApplicationHome h = new ApplicationHome(getClass());
File jarF = h.getSource();
System.out.println(jarF.getParentFile().toString());
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


