Cant find Resource Bundle

Hey all,

I have following Problem concerning i18n with ResourceBundles: I have a main Application which is exentible by Plugins. The Plugins are jar files which contains class files and property files for i18n. Loading the class files with a Classloader works fine, the problem occurs if i want to load the property Files with the ResourceBundle mechanism. He can磘 find the messages.properties file. When i add the jar to the classpath it works. But i dont want to add the jar file s to the classpath. What can i do? Here is my i18n method which fails...:

/**

* @param _key

*The Key to be found in the i18n-property file

* @param _source

*always submit "this" here.

* @return

*/

publicstatic String getString(String _key, Object _source){

String packageNameTemp = _source.getClass().getPackage().getName();

String packageName = packageNameTemp.replaceAll("\\.","/");

packageName +="/" +"messages";//$NON-NLS-1$

ResourceBundle b = ResourceBundle.getBundle(packageName, Locale.German);

String res = b.getString(_key);

return res;

}

Thanks for your help.

[1480 byte] By [OhNoa] at [2007-11-26 23:51:52]
# 1

hi,

try this instead

String packageName = packageNameTemp.replaceAll("\\.", ".");

packageName += "." + "messages"; //$NON-NLS-1$

I think the separator should be a simple dot "."

for example : com.mycompany.package1.Messages_en.properties

(i'm not sure this would helps u)

hth

Message was edited by:

java_2006

java_2006a at 2007-7-11 15:31:03 > top of Java-index,Java Essentials,Java Programming...
# 2
what is the actual filename of the resource?
georgemca at 2007-7-11 15:31:03 > top of Java-index,Java Essentials,Java Programming...
# 3
the actual filename(s) are messages_DE.properties and messages.properties
OhNoa at 2007-7-11 15:31:03 > top of Java-index,Java Essentials,Java Programming...
# 4
> the actual filename(s) are messages_DE.properties and> messages.propertiesand you're not using the ".properties" part of the resource's name.....
georgemca at 2007-7-11 15:31:03 > top of Java-index,Java Essentials,Java Programming...
# 5
> and you're not using the ".properties" part of the> resource's name.....No this is not necessary. It works properly with all messages.properties in the Framwork, only the i18n resource Bundles of the plug-in cant be loaded :-(.
OhNoa at 2007-7-11 15:31:03 > top of Java-index,Java Essentials,Java Programming...
# 6
> I think the separator should be a simple dot> "."getBundle will replace those dots with slashes anyway, along with appending ".properties" to the path name.
karma-9a at 2007-7-11 15:31:03 > top of Java-index,Java Essentials,Java Programming...
# 7

> I have following Problem concerning i18n with

> ResourceBundles: I have a main Application which is

> exentible by Plugins. The Plugins are jar files which

> contains class files and property files for i18n.

> Loading the class files with a Classloader works

> fine, the problem occurs if i want to load the

> property Files with the ResourceBundle mechanism.

Which classloader are you using for loading the Plugins class files? getBundle(name, locale) uses the caller's classloader.

Did you try getBundle(name, locale, classloader) ?

karma-9a at 2007-7-11 15:31:03 > top of Java-index,Java Essentials,Java Programming...
# 8

> > I think the separator should be a simple dot

> > "."

>

> getBundle will replace those dots with slashes

> anyway, along with appending ".properties" to the

> path name.

I tried the simple dot but it still doesn磘 work. Like i explained before it must have something to do with the classpath, because if i add the plug-in jar to the classpath, it works!

Is there any way to add this jar File to the classpath during runtime?

Message was edited by:

OhNo

OhNoa at 2007-7-11 15:31:03 > top of Java-index,Java Essentials,Java Programming...
# 9

> Which classloader are you using for loading the

> Plugins class files? getBundle(name, locale)

> uses the caller's classloader.

> Did you try getBundle(name, locale, classloader)

> ?

Kama-9 -> you got it! With the classloader it works! So you got the duke Stars ;-) Thanks a lot!!!

OhNoa at 2007-7-11 15:31:03 > top of Java-index,Java Essentials,Java Programming...