阅读背景:

springboot 获取jar包所在目录_必有缺的博客_springboot获取当前jar包路径

来源:互联网 

springboot 获取jar包所在目录

    /**
     * 如果已打成jar包,则返回jar包所在目录
     * 如果未打成jar,则返回target所在目录
     * @return
     */
    public static String getRootPath() throws UnsupportedEncodingException {
        // 项目的编译文件的根目录
        String path = URLDecoder.decode(PathUtil.class.getResource("/").getPath(), String.valueOf(StandardCharsets.UTF_8));
        if (path.startsWith("file:")) {
            int i = path.indexOf(".jar!");
            path = path.substring(0, i);
            path = path.replaceFirst("file:", "");
        }
        // 项目所在的目录
        return new File(path).getParentFile().getAbsolutePath();
    }
    /**
     * 如



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: