Reputation: 9478
when reading the properties file, iam getting nullpointer
exception.
faceConfig.load(ReadPropertyFile.class.getClassLoader().getResourceAsStream("/resources/faces.properties"));
below is the path of properties file facedetections/src/main/resources/faces.properties
i tried in different combinations as my class file that reads in below path /facedetections/src/main/java/com/facial/facedetection/utils/ReadPropertyFile.java
combinations are ../../../../../resource/faces.properties
, /resource/faces.properties
and
../../../resource/faces.properties
Please suggest what is the correct path i can provide for this.
Edit : I extracted the war file and providing its path below.
Upvotes: 0
Views: 925
Reputation: 1872
looks your property file under class folder not in resource. as your screen shot cant find resource folder under class folder.
So just use
ReadPropertyFile.class.getClassLoader().getResourceAsStream("faces.properties")
Upvotes: 2
Reputation: 43728
Since it is unlikely that you get a NPE when the file is not found I assume that faceConfig
is null
when you execute that line.
Upvotes: 0
Reputation: 7799
The path is relative to the point where the object (.class
) files are located. Are you sure you have configured your build/test tool to copy the resource file into that structure? Exactly where? That's what counts, not the position of the sources.
Additionally, my understanding is that getResourceAsStream()
of most ClassLoaders
do not support ..
notation.
The position where your resource file is currently located is out of reach of the ClassLoader
. If you move your file to /facedetections/src/main/java/resources/faces.properties
, then you will be able to use the current code
getResourceAsStream("resources/faces.properties")
I'm making assumptions about your environment. In particular, this is entirely dependent on classloaders. If this doesn't help, please provide object file location, not sources (unless it is the same, but state it).
Upvotes: 0