Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

本地配置,打成jar包后运行,报空指针异常。远程配置也无法读取zookeepe.properties的内容 #55

Open
yluwei opened this issue Oct 26, 2020 · 1 comment

Comments

@yluwei
Copy link

yluwei commented Oct 26, 2020

public static File toFile(URL url) {
logger.info("*********url:"+url.getFile()+""+url.getProtocol());

    if (url == null || !url.getProtocol().equals("file")) {
        return null;
    } else {
        String filename = url.getFile().replace('/', File.separatorChar);
        int pos = 0;
        while ((pos = filename.indexOf('%', pos)) >= 0) {
            if (pos + 2 < filename.length()) {
                String hexStr = filename.substring(pos + 1, pos + 3);
                char ch = (char) Integer.parseInt(hexStr, 16);
                filename = filename.substring(0, pos) + ch + filename.substring(pos + 3);
            }
        }
        return new File(filename);
    }
}

打成jar后,url.getProtocol()=“jar”,然后报错,应该怎么解决呢

@yluwei yluwei changed the title 本地配置,打成jar包后运行,报空指针异常 本地配置,打成jar包后运行,报空指针异常。远程配置也无法读取zookeepe.properties的内容 Oct 26, 2020
@prozhu
Copy link

prozhu commented Jan 28, 2021

首先确认问题点
一、如果是读取到配置文件中的信息为null,原因可能有以下几种

  1. 配置文件的路径有问题
  2. 打成jar包时,确认下配置文件是否也在jar里面

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants