Link to home
Start Free TrialLog in
Avatar of SumitSinghRawat
SumitSinghRawat

asked on

Placing properties file on Websphere application server

Hi,
I have a properites file that I am using to read the JNDI names for the datasources that I have to access. I am trying to access this property file using the resource bundle but I am sure that I have not placed the file in the correct location. Where do I place a properties file, that will be automatically available when I try to access it using the resource bundle. This file is different from the applicationResource.properties file that I am using along with struts and has a different name. Is there any configuration that needs to be done or can I overcome this problem by placing the file in a particular folder on WAS 5.1
Please help me on this!!!
thanks
Sumit
Avatar of JackOfAll1
JackOfAll1
Flag of United States of America image

The location of the properties can be any where you want.

We have what we call internal property files and external property files.  Internal property files are the files within the .ear.  All of the needed definations (defaults) are located in the internal property files.  We have empty external property files that are used only if we need to overwrite a value in the internal property files.  For example if I need to turn debug on I add a entry to the external property file and stop and start the application and I am done.  This allows us to keep all of the needed values within the build.  We have defined a variable on each of the machines that the application will run on (development, QA, Production) that is used to determine what values within the property files are used.  Seperate property files per machine can get confusing when it is time to configure the machine or migrate the application.  

For accessing the external property files we use the actual file path and names.  We have standards for file locations like

/application dir/resources/property file

Hope this helps.


Avatar of SumitSinghRawat
SumitSinghRawat

ASKER

Hi,
Yes the input given by you was very useful, I was not aware of the fact that I could use an internal property file and I was always under the impression that the property file is external.
If it is possible to keep an internal property file then , I need to know how do I access the internal property file for example :
I am using a class that implements the ServletContextListener and this class accesses a property file .
here is the piece of code:
public void contextInitialized(ServletContextEvent servletContextEvent) {
            String propFile = "sumit.properties";
                                File file = new File(propFile);            
            if (propFile != null) {
                  PropertyConfigurator.configure(file.getAbsolutePath ());
            }
            
            
      }
How will I have to do this implementation plus can I access the same property file using the Resource bundle.
I was stuck with this problem on , do I have to put the properties file in the EAR classpath, ie. in the manifest.mf file . I am very grateful to you that you finally replied to my question. If you could give me some more inputs it would be very helpful.
Thanks a Ton,
Sumit
Hi,

To access your Properties File from any server, Java had provided with one beautiful package, i.e ResourceBundle using this you can read your properties file from your application server location...so look for the ResourceBundle Documentation you will find very easy to implement this. No need to write any fileStreams / Readers/Writers...you can strait away use this Bundle ....

R.K
And to access your properties file, you no need that your .ear file or any file need to be in classpath...no need . You just deploy the package in server.

Look @ ResourceBundle concepts in JAVA-J2EE.

R.K
ASKER CERTIFIED SOLUTION
Avatar of rama_krishna580
rama_krishna580
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial