views:

23

answers:

1

I am reading properties file 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)

+1  A: 

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.

Marimuthu Madasamy
it returns null
Maddy.Shik
Make sure that the file is available in WEB-INF\classes\yourPackage\error.properties
Marimuthu Madasamy
currently i am testing it by JUnit test cases. Its located as MyProject/conf/dao/error.propertiesI have specified classpath as MyProject/confSo i am specifying file path while retrieval as dao/error.propertiesBut its returning null
Maddy.Shik
Try /dao/error.properties
Marimuthu Madasamy