从外部Jar加载属性文件

时间:2014-11-04 05:28:45

标签: java jar properties-file

我有一个属性文件,存在于某个外部jar中。 在给定外部jar的路径的情况下,如何在java中加载此属性文件? (我知道jar中存在prperties文件的位置)

例如,jar文件:/home/jars/abc.jar   在这个罐子里面我有prop / abc.properties。

请注意,类路径中不存在jar(因此我不能使用getResourcesAsStream),而是在运行时获取jar的路径。

1 个答案:

答案 0 :(得分:0)

JarFile jarFile = new JarFile("path/to/jarFile.jar");
InputStream inputStream = jarFile.getInputStream(jarFile.getEntry("path/inside/the/jar/to/propFile.properties"));
Properties properties = new Properties();
properties.load(inputStream);