2014-11-04 143 views
0

我有一个属性文件存在于某个外部jar中。 如何在java中加载这个属性文件,给定外部jar的路径? (我知道jar文件中的属性文件在哪里)从外部Jar加载属性文件

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

请注意,该jar没有出现在类路径中(所以我不能使用getResourcesAsStream),而是在运行时获取jar的路径。

回答

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);