marcil.david
asked on
Problem with Class loader for ResourceBundles
I'm having problems with the class loader for ResourceBundles. Here is
some background....
I've created some ListResourceBundles (eg. LabelBundle,
LabelBundle_en_US, etc.) and I've put them in a package (
com.canadatrust.util ) when I have an applet or application try and access the bundle using the following
def_locale = Locale.getDefault();
def_rb =
ResourceBundle.getBundle(" com.canada trust.util .LabelBund le",
def_locale);
I keep getting a missing resource exception...
java.util.MissingResourceE xception: can't find resource
for com.canadatrust.util.Label Bundle_en_ US
Does the resource class loader use the CLASSPATH under Win32? I've done everything I can think of. I've changed my CLASSPATH to point directly to the package and it still does not find it.
Any help would be appreciated.
Thanks, David
some background....
I've created some ListResourceBundles (eg. LabelBundle,
LabelBundle_en_US, etc.) and I've put them in a package (
com.canadatrust.util ) when I have an applet or application try and access the bundle using the following
def_locale = Locale.getDefault();
def_rb =
ResourceBundle.getBundle("
def_locale);
I keep getting a missing resource exception...
java.util.MissingResourceE
for com.canadatrust.util.Label
Does the resource class loader use the CLASSPATH under Win32? I've done everything I can think of. I've changed my CLASSPATH to point directly to the package and it still does not find it.
Any help would be appreciated.
Thanks, David
ASKER
Yes the class has been compiled
What happens if you copy the bundle to create the
default bundle "LabelBundle"? Same error message?
default bundle "LabelBundle"? Same error message?
ASKER
Yes I have a default bundle LableBundle under the same package com.canadatrust.util.Label Bundle.cla ss.
Strange, sounds like it should be working.
How are you running your class: java, appletviewer, browser?
Which is the current directory, when you run it?
What does you CLASSPATH look like?
How are you running your class: java, appletviewer, browser?
Which is the current directory, when you run it?
What does you CLASSPATH look like?
ASKER
I'm running it from a directory called d:\javadev and my classpath is below....
SET CLASSPATH=.;d:\javadev\;c: \jdk1.1.2\ lib\classe s.zip;d:\j avadev\fpc lass.zip;
The file fpclass.zip is a zip file containing all our classes. It is zipped with no compression and works fine for loading classes.
Have you put any resource classes in packages and had them load?
Thanks, David
SET CLASSPATH=.;d:\javadev\;c:
The file fpclass.zip is a zip file containing all our classes. It is zipped with no compression and works fine for loading classes.
Have you put any resource classes in packages and had them load?
Thanks, David
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The resource classes are not contained in the zip. Could I ask a couple of questions about your test package. Did you have the resource classes in the same directory (package) as the calling class? When you loaded the class using ResourceBundle.getBundle did you qualify it with the package?
Here's my test application:
- all classes in the same package
- getBundle uses fully qualified name; this is a must!
BTW, resources were found if I ran the program from the package root directory, e.g.
java resPkg.Test
but not if I ran the program from within the resPkg directory, e.g.
java Test
// file Test.java -------------------------- ---------- ------
package res.resPkg;
import java.util.*;
public class Test {
public static void main (String[] args) {
Locale defLoc = Locale.getDefault();
System.out.println(defLoc) ;
ResourceBundle rb =
ResourceBundle.getBundle(" resPkg.lab elbundle", defLoc);
System.out.println(rb.getS tring("tes tKey"));
}
}
// file labelbundle.java -------------------------- ----------
package res.resPkg;
import java.util.*;
public class labelbundle extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
{ "testKey", "testKey_base" }
};
}
// file labelbundle_de.java -------------------------- ----------
package res.resPkg;
import java.util.*;
public class labelbundle_de extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
{ "testKey", "testKey_de" }
};
}
- all classes in the same package
- getBundle uses fully qualified name; this is a must!
BTW, resources were found if I ran the program from the package root directory, e.g.
java resPkg.Test
but not if I ran the program from within the resPkg directory, e.g.
java Test
// file Test.java --------------------------
package res.resPkg;
import java.util.*;
public class Test {
public static void main (String[] args) {
Locale defLoc = Locale.getDefault();
System.out.println(defLoc)
ResourceBundle rb =
ResourceBundle.getBundle("
System.out.println(rb.getS
}
}
// file labelbundle.java --------------------------
package res.resPkg;
import java.util.*;
public class labelbundle extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
{ "testKey", "testKey_base" }
};
}
// file labelbundle_de.java --------------------------
package res.resPkg;
import java.util.*;
public class labelbundle_de extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
{ "testKey", "testKey_de" }
};
}
your resourceBundle? I.e. is there a class file
\com\canadatrust\util\Labe