• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how can i get the path from which resource bundle gets its bundle file

 
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all
im using resource bundle to load values from properties files , i like to know
from where the resource bundle load its properties file in the classpath
is there away to do this ?
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is safer and more securer if you use ResourceBundle to load .properties file. You can write it by yourself as simple way. It use classLoader and stream to load file as its locale
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i do use RB to load the files , i just need to know from whice path i load them
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Resource bundle will check the class path and compare with your file name. if it able to match then it will load the file as the property file. here the location is all about the class path.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder if you could create a custom ClassLoader that calls a listener any time it succeeds ...

That gives you all you need to map names to URLs.
 
ben josh
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont understand how can i implement it so it will give me the path
of the prop file the RB found
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I left a lot out of that suggestion.

First, read up on ClassLoaders. You can write a custom ClassLoader that extends URLClassLoader and override the method I showed before. When it succesfully loads a class, it calls a listener object with name and full classname. You might pass that listener object to your ClassLoader in the ClassLoader constructor.

Then pass your own ClassLoader to ResourceBundle.get().

Now ResourceBundle calls the ClassLoader over and over, once for each candidate name that it might load. When it actually finds a file, the loader will call your listener and you save off the information. When ResourceBundle returns you a bundle, the info you saved should be the latest file loaded.

I can't guarantee this will work out ... give it a try and see!
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic