SpringBoot (解决发布后找不到项目路径,jar的路径) 。获取当前项目路径、 和 发布后获取当前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();
    }

你可能感兴趣的:(springboot)