如何从Jar文件中读取WEB-INF中存在的属性文件

时间:2020-12-01 17:17:58

I have a jar file(an api), from which i need to load a property file which exists in WEB-INF folder. How do i load this property file from my jar.

我有一个jar文件(一个api),我需要加载一个存在于WEB-INF文件夹中的属性文件。如何从我的jar加载此属性文件。

Would appreciate any help.

非常感谢任何帮助。

1 个解决方案

#1


0  

You can easily do it if your properties file is in WEB-INF/classes. In this case just write something like

如果属性文件位于WEB-INF / classes中,则可以轻松完成。在这种情况下,只需写一些东西

Properties props = new Properties();
props.load(getClass().getResourceAsStream("/myprops.properties"));

Obviously the file may be located in sub folder of classes. In this case you have to specify the full path when calling getResourceAsStream().

显然,该文件可能位于类的子文件夹中。在这种情况下,您必须在调用getResourceAsStream()时指定完整路径。

#1


0  

You can easily do it if your properties file is in WEB-INF/classes. In this case just write something like

如果属性文件位于WEB-INF / classes中,则可以轻松完成。在这种情况下,只需写一些东西

Properties props = new Properties();
props.load(getClass().getResourceAsStream("/myprops.properties"));

Obviously the file may be located in sub folder of classes. In this case you have to specify the full path when calling getResourceAsStream().

显然,该文件可能位于类的子文件夹中。在这种情况下,您必须在调用getResourceAsStream()时指定完整路径。