简体   繁体   English

从外部Jar加载属性文件

[英]Loading a Properties File From an External Jar

I have a properties file which is present in some external jar. 我有一些外部jar中存在的属性文件。 How do I load this properties file in java, given the path to the external jar? 给定外部jar的路径,如何在Java中加载此属性文件? (I know where the prperties file is present inside the jar) (我知道罐子里的prperties文件在哪里)

Eg., jar file : /home/jars/abc.jar Inside this jar I have prop/abc.properties. 例如,jar文件:/home/jars/abc.jar在这个jar中,我有prop / abc.properties。

Note that the jar is not present in the classpath ( so I cannot use getResourcesAsStream), rather the path to the jar is obtained at run time. 请注意,罐子不在类路径中(因此我不能使用getResourcesAsStream),而是在运行时获取罐子的路径。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM