获取jar包所在路径


public String getJarPath() {
    String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
    if (System.getProperty("os.name").contains("dows")) {
        path = path.substring(1, path.length());
    }
    if (path.contains("jar")) {
        path = path.substring(0, path.lastIndexOf("."));
        return path.substring(0, path.lastIndexOf("/"));
    }
    path = path.replace("target/classes/", "");
    //路径中字符处理
    return URLDecoder.decode(path, StandardCharsets.UTF_8);
}

文章作者: PudgeLee
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 PudgeLee !
评论