Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

ResourceBundle can't find properties file unless in package

Thread view: 
charles.hajj@gmail.com - 24 Apr 2006 18:42 GMT
Hello,

I am using the ResourceBundle to load properties files for i18n

I have this strcuture :

-<My Project>
    -conf
       -locale
          -MessageBundle.properties
          -MessageBundle_en.properties
    -src
       -com.cha.core.locale.<MyClass>

in <MyClass> I am using the following code :

ResourceBundle messages =
ResourceBundle.getBundle("conf/locale/MessagesBundle", m_locale);

As you see, I need to isolate the configuration files in the conf
directory. The properties files are now under <Working
Dir>\conf\locale.

However, getBundle() can't find them
(java.util.MissingResourceException) unless they are under the source
directory (src in my case)

Could you please help on that issue.
Thomas Fritsch - 24 Apr 2006 19:26 GMT
> ResourceBundle messages =
> ResourceBundle.getBundle("conf/locale/MessagesBundle", m_locale);
Use
 ResourceBundle.getBundle("conf.locale.MessagesBundle", m_locale);
instead.

Signature

"Thomas:Fritsch$ops.de".replace(':', '.').replace('$', '@')

Roland de Ruiter - 24 Apr 2006 19:40 GMT
> Hello,
>
[quoted text clipped - 24 lines]
>
> Could you please help on that issue.

Make sure that <WorkingDir> is in the classpath when you run your
application. Assuming the compiled class files are in <BinDir> (which
could be the same as your 'src' directory), the commandline to start
your app should be like this:

java -classpath <BinDir>;<WorkingDir> your.pkg.Application

[If you are running Unix/Linux, replace the separator ; in the classpath
by :]

Signature

Regards,

Roland

Carlitto - 24 Apr 2006 19:52 GMT
Thanks to you all.

However, I don't want the workingdir to be in the classpath. Only
source files. and the output directory is different also (src, classes)
ResourceBundle loads file if they are part of the classpath.

Is there any way to load a property file outside the classpath (a
seperate conf directory in the workingdir) using ResourceBundle ? If
not, how can I load properties files for i18n other that using
ResourceNundle?

Thanks.

Charles.
Roland de Ruiter - 24 Apr 2006 21:32 GMT
> Thanks to you all.
>
[quoted text clipped - 10 lines]
>
> Charles.

Write your own class loader (subclass java.lang.ClassLoader) and implement
    protected URL findResource(String name)
which locates the resource in your workingdir.

Then use ResourceBundle#getBundle(String,Locale,ClassLoader) with your
own class loader instance.

Signature

Regards,

Roland

Carlitto - 24 Apr 2006 22:32 GMT
Roland,

Thanks, it worked I overrided URL findResource(String name) in my
custom ClassLoader:

protected URL findResource(String name)
    {
        File f = new File(name);

        try
        {
            return f.toURL();
        }
        catch (MalformedURLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return super.findResource(name);
    }

Cheers,

Charles.
Thomas Hawtin - 26 Apr 2006 20:28 GMT
> Thanks, it worked I overrided URL findResource(String name) in my
> custom ClassLoader:
>
> protected URL findResource(String name)

Why not just use java.net.URLClassLoader.newInstance?

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.