2014-11-04 152 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);