SpringBoot 获取当前项目路径 和 发布后获取当前jar的路径

SpringBoot 获取当前项目路径 和 发布后获取当前jar的路径

/**
     * 获得项目工程的绝对路径
     */
    public static String getWebRoot(HttpServletRequest request) {
        return request.getSession().getServletContext().getRealPath("/");
    }

    /**
     * 获得发布后的jar当前路径
     */
    public String getJarRoot(){
        ApplicationHome home = new ApplicationHome(getClass());
        File jarFile = home.getSource();
        return jarFile.getParentFile().getPath();
    }

猜你喜欢

转载自blog.csdn.net/fangchao2011/article/details/88746964