I use the ResourceBundle.getBundle(MyClass.class.getName(), myLocale) in my
Super Class to to get the property data.  This way, I can also have
MyClass.properties, or MyClass_xx.properties as part of my class package.

Bellow are examples of MyClass with 2 set of property files.

Regards,
t.a.

-------- MyClass.properties ----
MyClass.Hello="Hello There.  This is a test."

-------- MyClass_fr.properties ----
MyClass.Hello="Bonjour L�. C'est un essai."

-------- MyClass.java ----
public MyClass extends MySuperClass {
   public void main(String[] arg) {
      MyClass mc_default = new MyClass();
      System.out.println(mc_default.getString("MyClass.Hello");
      MyClass mc_french = new MyClass();
      mc_french.setLocale(Locale.FRENCH);
      System.out.println(mc_french.getString("MyClass.Hello");
   }
}

-------- MySuperClass.java ----
public MySuperClass {
   private ResourceBundle myBundle;
   private Locale locale;

   // ....

   public Locale getLocale() {
       if (locale == null) {
           locale = Locale.getDefault();
       }
       return locale;
  }

  public void setLocale(Locale locale) {
     this.locale = locale;
  }

   public ResourceBundle getMyBundle() {
      if (myBundle == null) {
         myBundle = ResourceBundle.getBundle(this.class.getName(), getLocale());
     }
      return myBundle();
   }

   public setMyBundle(ResourceBundle myBundle) {
      this.myBundle = myBundle;
   }

   public String getString(String key) {
      return getMyBundle().getString(key);
   }
}
----- Original Message ----- 
From: "A. Kevin Baynes" <[EMAIL PROTECTED]>
To: "Research Triangle Java User's Group mailing list." <[EMAIL PROTECTED]>
Sent: Monday, December 15, 2003 9:33 AM
Subject: RE: [Juglist] Where is that Properties File


>
> 1) You can use getResource() within your code to find a properties file that
> is included in your jar. Check out Class.getResource() and
> Classloader.getResource().
>
> 2) The longer way around is to locate the jar and extract the resource
> manually : http://www.javaworld.com/javatips/jw-javatip49.html
>
> ~akb
>
>
> | -----Original Message-----
> | From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> | Behalf Of Harold Meder
> | Sent: Sunday, December 14, 2003 7:53 PM
> | To: [EMAIL PROTECTED]
> | Subject: [Juglist] Where is that Properties File
> |
> |
> | I have defined a properties file for my java application.  It
> | lives in a folder with my java code.  Eclipse nicely moves it over to
> | my classes folder, where it also places my class files.
> | Everything works nicely.
> |
> | I package up my application into a jar file, including the
> | properties file.  My application can no longer find the properties file.
> | Of course, if I copy my properties file into an appropriate
> | folder structure in a folder listed in my class path, it works again.
> |
> | I do not want to have to deploy my application with my properties
> | file outside the jar file.  Not this one anyway.
> |
> | How can I get my application to find my properties file inside of
> | the jar file?  What is the proper what to deploy properties files
> | with your application?
> |
> | Thank you,
> |    Harold Meder.
> |
> |
> |
> | _______________________________________________
> | Juglist mailing list
> | [EMAIL PROTECTED]
> | http://trijug.org/mailman/listinfo/juglist_trijug.org
>
>
> _______________________________________________
> Juglist mailing list
> [EMAIL PROTECTED]
> http://trijug.org/mailman/listinfo/juglist_trijug.org
>


_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to