在maven资源目录src / main / resouces中获取路径属性文件 [英] Get the path a propertie file in the maven resource directory src/main/resouces
问题描述
我想从我在maven资源目录(src / main / resouces)中的属性文件读取。
属性文件的路径称为: src / main / resouces / jsfatwork / messages
i want to read from my propertie file in the maven resource directory (src/main/resouces).
The path to the propertie file is called: src/main/resouces/jsfatwork/messages
该文件称为test.properties。
我使用JSF 2.2,Eclipse,Java Web Project
webapp在Tomcat 7上运行
The file is called test.properties. I used JSF 2.2, Eclipse, Java Web Project The webapp runs on a Tomcat 7
我写入maven pom.xml文件:
I write in the maven pom.xml file:
<resources>
<resource>
<directory>${basedir}/src/main/resouces/jsfatwork/messages</directory>
<include>**/test.properties</include>
</resource>
</resources>
并写入我的java文件:
属性prop = new Properties();
And write in my java file: Properties prop= new Properties();
Properties properties = new Properties();
try {
//load a properties file
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"));
} catch(Exception e) {
}
但是它不找到属性文件。
我可以读出路径如何在 Thread.currentThread()。getContextClassLoader()。getResourceAsStream
?
But it don't find the propertie file.
Can i read out the path how is find in the Thread.currentThread().getContextClassLoader().getResourceAsStream
?
推荐答案
尝试使用
properties.load(ThisClass.class.getResourceAsStream("/jsfatwork/messages/test.properties"));
这篇关于在maven资源目录src / main / resouces中获取路径属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!