jboss: accessing file resource through java code?
I am reading properties fi开发者_如何学运维le from java DAO implementation for loading properties object as in code given below
this.getErrorproperties().load(
new FileInputStream(new File("").getAbsolutePath()
+ "/conf/error/error.properties"));
While testing it works fine but when i try to deploy application on jboss 5 server. application deployment fails because absolute path is considered to be bin directory of jboss.
I want Jboss to find it relative to path of ear file. One more problem i face is my path relative to home path of project or ear file will be different for first and later.
Please suggest current approach programmers follow for such scenario. (I am a fresher)
You need to have your properties file in your classpath. If you have your properties file in the package foo.bar then you can load the properties file using,
this.getErrorproperties().load(getClass().getResourceAsStream("/foo/bar/error.properties"))
The leading slash in the path indicates an absolute path. Without the leading slash, the path is relative to the package of the class in.
精彩评论