0

Can I configure my web.xml to look for the resources(like properties file) to a particular position.

Like during the build am not adding any properties file to WEB-INF/classes folder, what I want to achieve is that during runtime it should get the required properties file from specified position defined in web.xml!!

How to achieve it??

Sharique
  • 781
  • 5
  • 12
  • 33

1 Answers1

2

have you tried to just define a variable in your web.xml naming an environment variable pointing to your properties file?

like: export CFG_LOCATION="/var/local/config/mycfg.properties"

and in web.xml

<context-param>
  <param-name>cfg_localtion_variable_name</param-name>
  <param-value>CFG_LOCATION</param-value>
</context-param>
NeoP5
  • 611
  • 7
  • 19
  • also have a look here: http://stackoverflow.com/questions/2948992/using-properties-in-web-xml – NeoP5 Mar 23 '15 at 10:53
  • by the way... putting configuration values inside a compiled-applicaiton is most-time a bad idea except they are static (like localization). to configure your application use the method above, or read your values from database cfg-table by using a datasource with jndi-lookup. – NeoP5 Mar 23 '15 at 11:00
  • the thing is, I have to deploy multiple war file in single tomcat, and those war files are using properties file of same name but key-value pair inside properties file may differ... so in order to get it done I have configure it in such a way that if request comes from abc.war(suppose webapp name is abc) then it should go to its respective location and pick those properties file, and I can't change the code...So I have to do like that or any other way is there without changing code? – Sharique Mar 23 '15 at 11:52
  • Hi i did it in the following way. I just pointed my variable to a directory instead of a file. The file name of the properties file is excatly the same as my servlet-context. so for an application registered as "http://localhost:8080/abc/" by properties file is abc.properties in $CFG_LOCATION directory. If you are using spring check out PropertyPlaceholderConfigurer – NeoP5 Mar 23 '15 at 12:07
  • I am not using spring – Sharique Mar 23 '15 at 16:29
  • Of course this can also be done using your own class e.g. providing a static instance of your Properties if you are not using spring. ;) – NeoP5 Mar 24 '15 at 17:55