本地打包到linux上面,读取外部conf的配置文件(如logj)
1.获取当前类路径路径
CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource();
File jarFile = new File(codeSource.getLocation().toURI().getPath());
2.获取当前jar包路径
String jarDir = jarFile.getParentFile().getPath();
3.根据需要自己配置路径
//配置文件名称
private String CONFIG_FILE_NAME = "/config.properties";
BufferedReader bufferedReader = new BufferedReader(new FileReader(jarDir+"../conf"+CONFIG_FILE_NAME));
PATH_NAME=bufferedReader.toString();
4. 使用 Properties加载
Properties prop = new Properties();
prop.load(bufferedReader);