Placing properties file on Websphere application server

Posted on 2005-03-29
Medium Priority
Last Modified: 2008-01-09
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!!!
Question by:SumitSinghRawat
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 13767261
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.


Author Comment

ID: 13777453
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,
LVL 23

Expert Comment

ID: 14105873

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 ....

LVL 23

Expert Comment

ID: 14105881
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.

LVL 23

Accepted Solution

rama_krishna580 earned 750 total points
ID: 14105887

import java.util.*;
public class ResourceBundleExample {
   public static void main(String args[]) throws MissingResourceException {
     String resourceName = "RBExample";
     ResourceBundle rb;
     // Default locale
     rb = ResourceBundle.getBundle(resourceName);
     System.out.println("Default : " + rb.getString("Hello" + ".text"));
     // Request a resource bundle with explicitly specified locale
     rb = ResourceBundle.getBundle(resourceName, Locale.GERMANY);
     System.out.println("German : " + rb.getString("Hello" + ".text"));
     // No property file for China in this example... use default
     rb = ResourceBundle.getBundle(resourceName, Locale.CHINA);
     System.out.println("Chinese : " + rb.getString("Hello" + ".text"));
     // Here is another way to do it...
     rb = ResourceBundle.getBundle(resourceName);
     System.out.println("French : " + rb.getString("Hello" + ".text"));
     // No property file for China in this example... use default, which is now fr_FR.
     rb = ResourceBundle.getBundle(resourceName, Locale.CHINA);
     System.out.println("Chinese : " + rb.getString("Hello" + ".text"));

For more example(s) you may look @ here...


Featured Post

ATEN's HDBaseT Presentation at InfoComm 2017

Hear ATEN Product Manager YT Liang review HDBaseT technology, highlighting ATEN’s latest solutions as they relate to real-world applications during her presentation at the HDBaseT booth at InfoComm 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert websphere application server default chained Certificates from 1024 to 2048 keysize or higher size and also you can change signatureAlgorithm . Please make sure Websphere Application Server fixpack or Above. The following steps a…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question