springboot 获取当前Jar包当前所在目录

ppylox
·9/26/2021·0 阅读
AI 摘要模型根据正文自动生成,仅供参考

本文介绍在Spring Boot中获取当前Jar包所在目录的方法。通过创建ApplicationHome对象并传入任意类(如JwtAuthService.class),调用getSource()获取Jar文件路径,再用getParentFile()取得其父目录,转换为字符串后即可得到Jar包当前所在目录,最后用System.out.println输出结果。

// 获取当前目录
ApplicationHome ah = new ApplicationHome(JwtAuthService.class);
String docStorePath = ah.getSource().getParentFile().toString();
System.out.println(docStorePath);

相关文章

评论 (0)

暂无评论,来写第一条吧