Initialising ResourceBundles in different dir:

Discussion in 'Java' started by t12be, May 10, 2004.

  1. t12be

    t12be Guest

    Need help,

    Is it possible to initialise a ResourceBundle from another dir?
    In the example beneath this file has to be within the same dir of the
    source files. I would like to seperate them, how?

    ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
    Locale("en","US"));

    I looked through the API and didn't find anything.
     
    t12be, May 10, 2004
    #1
    1. Advertising

  2. On Mon, 10 May 2004 08:44:17 -0700, t12be wrote:

    > Need help,
    >
    > Is it possible to initialise a ResourceBundle from another dir? In the
    > example beneath this file has to be within the same dir of the source
    > files. I would like to seperate them, how?
    >
    > ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
    > Locale("en","US"));
    >
    > I looked through the API and didn't find anything.


    You can pass in a ClassLoader to the getBundle() method. This ClassLoader
    will determine where ResourceBundle will search for the bundle.
    URLClassLoader will best serve your needs.

    HTH,
    La'ie Techie
     
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=, May 10, 2004
    #2
    1. Advertising

  3. t12be

    t12be Guest

    L??ie Techie <laie@wing_this_etsolutions.com> wrote in message news:<>...
    > On Mon, 10 May 2004 08:44:17 -0700, t12be wrote:
    >
    > > Need help,
    > >
    > > Is it possible to initialise a ResourceBundle from another dir?
    > >...


    >
    > You can pass in a ClassLoader to the getBundle() method. This ClassLoader
    > will determine where ResourceBundle will search for the bundle.
    > URLClassLoader will best serve your needs.
    >...


    First of all thanks of the answer. Only I didn't get out of it. Looked
    op how the URLCLassloader works but couldn't get it working. Maybe you
    can help me on?

    Have the following situation:
    +++++++++++++++++++++++++++++
    ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
    Locale("en","US"));

    And the 'langBundle' files are in this dir (relative from src dir)
    "../props/"
    So I tried the following:
    +++++++++++++++++++++++++
    URL[] urls = new URL[1];
    urls[0] = new URL("../props/");
    ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
    Locale("en","US"), new URLClassLoader(urls));

    Wich didn't work. Has it something to do with the relative url?? Read
    something like using relative urls like the need to get a base for the
    url by code like this: NameOfClass.class.getResource("")

    thx
    t12be
     
    t12be, May 14, 2004
    #3
  4. t12be wrote:
    > So I tried the following:
    > +++++++++++++++++++++++++
    > URL[] urls = new URL[1];
    > urls[0] = new URL("../props/");
    > ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
    > Locale("en","US"), new URLClassLoader(urls));
    >
    > Wich didn't work. Has it something to do with the relative url??


    What URL? "../props/" is a path, not an URL. You have to prepend it
    with "file:", maybe add some slashes.
     
    Michael Borgwardt, May 14, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    434
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. Andreas Schmidt
    Replies:
    0
    Views:
    379
    Andreas Schmidt
    Nov 7, 2003
  3. t12be
    Replies:
    0
    Views:
    354
    t12be
    May 2, 2004
  4. Fred Flintstone

    ResourceBundles - how to locate on Orion

    Fred Flintstone, Sep 3, 2004, in forum: Java
    Replies:
    7
    Views:
    460
    Sudsy
    Sep 5, 2004
  5. Matthew Denner
    Replies:
    1
    Views:
    188
Loading...

Share This Page