I\'m using a class to get a property file under the source folder. But it doesn\'t work! After checking, I found that the default path by using
File f = new File
You should use getResourceAsStream
, or similar. See this post for how to access resources. (This is independent of Glassfish - it applies to all Java EE app servers.)
See also this JavaWorld article.
Update: If your file is in the location src/ss.properties
, check that it has been copied to WEB-INF/classes
. Then, you should be able to access it with the following code:
InputStream propStream = ClassLoader.getResourceAsStream("ss.properties");
or (note leading slash if using the method in java.lang.Class
)
InputStream propStream = Class.getResourceAsStream("/ss.properties");
Note that the full file name (including the .properties
extension) needs to be used.
If neither of these work, please replace the getResourceAsStream
call with getResource(...).openStream()
and post details of the exception which should be thrown.