• Post Reply Bookmark Topic Watch Topic
  • New Topic

Properties file

 
Rama Raghavan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Are properties files still used in J2EE development ? (i.e. is it rather recommended to place all configuration information in web.xml or in properties file)
2. When I try to load a property file (without specifying explicit pathname), it seems to be loading from the root of my app server container.
Any thoughts ?
Rama
[ March 14, 2002: Message edited by: Rama Raghavan ]
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a J2EE application on Weblogic 6.1 and we are using property files for settings that woould otherwise not be appropriate or accessible using J2EE xml descriptors.
Lets say we have a property file named "enterprise.properties" located in a directory named "props", and this directory is also on the CLASSPATH. So, you can use the following code to get the property file:
java.util.PropertyResourceBundle properties = (PropertyResourceBundle)java.util.ResourceBundle.getBundle( "enterprise");
Note that when you call ResourceBundle.getBundle(), the argument you pass is essentially the name of the property file minus the ".properties" extenstion. This method will find the property file for you provided that it is located on the CLASSPATH.
Hope it helps,
SAF
 
Rama Raghavan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was quick, Thanks SAF.
Could you share what/why is it not appropriate or not accessible from xml descriptors..
Thanks again.
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'm currently using an EAR file to package a single web application that uses an EJB, also located in the EAR. The problem is that there is a JAR file in the root of the EAR that contains a class that needs to access environmant properties in order to initialize itself. Since this class exists at the EAR root level, it cannot access the web.xml file of the web application, which would be great because you can store environment properties in web.xml. Also, I can't store environment properties in the EAR descriptor, "application.xml", because it doesn't support the <env-entry> tag. So, I'm left with creating a ".properties" file and placing it in my EAR. It works fine.
SAF
 
great veera
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rama,
It's always better to have the values for all your configurations in properties file,either you can read it using SAF's way or you can write component to read properties file,when ever you don't want to hardcode values in your program ,you can put that value in properties file.So that if want to change the values you don't have to change your code.hence you can avoid compilation ,deployment.
Regards
Veera
 
Rama Raghavan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that parametes to the program are best stored outside the code to avoid compilation when values change, esp. for deployment.
My confusion is should it be:
1. properties file- where the app/servlet/bean reads the file
2. web app descriptors, where the container loads these parameters on deployment
Rama
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!