Solved

Problem with Class loader for ResourceBundles

Posted on 1997-06-27
9
208 Views
Last Modified: 2013-11-23
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.canadatrust.util.LabelBundle",
def_locale);

I keep getting a missing resource exception...

                java.util.MissingResourceException: can't find resource
for com.canadatrust.util.LabelBundle_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

0
Comment
Question by:marcil.david
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:mann061997
ID: 1222331
Sorry if this is stating the obvious...have you compiled
your resourceBundle? I.e. is there a class file
\com\canadatrust\util\LabelBundle_en_US.class ?

0
 

Author Comment

by:marcil.david
ID: 1222332
Yes the class has been compiled
0
 
LVL 1

Expert Comment

by:mann061997
ID: 1222333
What happens if you copy the bundle to create the
default bundle "LabelBundle"? Same error message?
0
 

Author Comment

by:marcil.david
ID: 1222334
Yes I have a default bundle LableBundle under the same package com.canadatrust.util.LabelBundle.class.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:mann061997
ID: 1222335
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?
0
 

Author Comment

by:marcil.david
ID: 1222336
I'm running it from a directory called d:\javadev and my classpath is below....

SET CLASSPATH=.;d:\javadev\;c:\jdk1.1.2\lib\classes.zip;d:\javadev\fpclass.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

0
 
LVL 1

Accepted Solution

by:
mann061997 earned 100 total points
ID: 1222337
OK, I wrote a little test package to study the problem and came up with the following results:

- works OK from normal, non-zipped class files
- fails to find resources if classes are zipped

I thought the problem might be that the zip-file contains truncated 8.3 directory names (on a FAT file system) but shortening the names didn't help.

My suggestion is to keep your resource files as unzipped class files for the time being. At least your program should work then. It really looks as though there is a bug in name resolution in zip files.
0
 

Author Comment

by:marcil.david
ID: 1222338
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?

 
0
 
LVL 1

Expert Comment

by:mann061997
ID: 1222339
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.labelbundle", defLoc);
    System.out.println(rb.getString("testKey"));
  }
}

// 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" }
  };
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java  and programming certification ? 4 86
JDeveloper 12c for 32 bit 4 71
eclipse compiler vs Installed JREs option 3 77
VB Script to add site to Java Exception List 4 53
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now