0

my project structure is following

projectxyz
  src
    com.example
        abc.java
  resources
        abc.properties

i want to read the property file from abc.java. How can i do that using Resource Bundle. I know how to use Resource Bundle.

ResourceBundle bundle =ResourceBundle.getBundle("resources\\ApplicationResources.properties");

But this code did not work.The problem is in the path of property file. How to get the path of the file outside the src folder ??

sareeshmnair
  • 441
  • 1
  • 6
  • 18

3 Answers3

1

your project structure looks like maven. So after compilation there will not be any resources folder inside your war file. Whatever folders are there inside resources folders will be in the WEB-INF folder after compilation. So you have to give the path from /WEB-INF.

If you are using struts2 then the above step is not required.Just create a file names struts.properties under resources folder, and add this below entry in that file.

struts.custom.i18n.resources = ApplicationResources

This does the trick.

Sivaranjani D
  • 512
  • 4
  • 16
0

Try without the .properties...

ResourceBundle bundle =ResourceBundle.getBundle("resources\\ApplicationResources");

Also, refer this

Community
  • 1
  • 1
Hirak
  • 3,601
  • 1
  • 22
  • 33
  • didn't worked. is it possible place the file outside the src folder. – sareeshmnair Mar 11 '14 at 04:53
  • Properties file needs to be in the classpath.. and that may be outside the src folder. Or property file path can be absolute pointing to the physical location of the file. Could you post what is the error you are getting after making this change? – Hirak Mar 11 '14 at 04:59
  • HTTP Status 500 - Unable to instantiate Action, com.example.abc, defined for 'login' in namespace '/'Can't find bundle for base name resources\ApplicationResources, locale en_US – sareeshmnair Mar 11 '14 at 05:02
0
Do not write .properties:
And also ensure that properties file is in classpath else specify the full path using ..\\..

ResourceBundle bundle =ResourceBundle.getBundle("ApplicationResources");
Sambhav
  • 217
  • 2
  • 16