users@glassfish.java.net

GF 3.1.1 ResourceBundles, classloading and applib classloader - MissingResourceException

From: Bernhard Thalmayr <bernhard.thalmayr_at_painstakingminds.com>
Date: Wed, 23 Nov 2011 12:13:03 +0100

Hi experts,

I'm trying to understand how I can leverage'Applib' classloader.

Following simple Web-app with one jsp having the scriptlet

" <%
  ResourceBundle bundle = RBLoader.loadResourceBundle();
%>"

The class 'RBLoader' receides in lib 'RBLib.jar'

The class itself looks like

public class RBLoader {
    private static final String BUNDLE_NAME = "testconfig";

    public static ResourceBundle loadResourceBundle() {
        ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME);
        return bundle;
    }

}

The resource bundle file is put into 'TestBundle.jar'

jar tvf <instance-dir>/lib/applibs/TestBundle.jar
     0 Wed Nov 23 11:25:18 CET 2011 META-INF/
    65 Wed Nov 23 11:25:18 CET 2011 META-INF/MANIFEST.MF
    24 Wed Nov 23 11:23:40 CET 2011 testconfig.properties

Why do I get a 'MissingResourceException'

[#|2011-11-23T11:55:39.186+0100|WARNING|glassfish3.1.1|javax.enterprise.system.c
ontainer.web.com.sun.enterprise.web._vs.server|_ThreadID=97;_ThreadName=Thread-1
6;|StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp
threw e
xception
java.util.MissingResourceException: Can't find bundle for base name
testconfig,
locale en_US
        at
java.util.ResourceBundle.throwMissingResourceException(ResourceBundle
.java:1499)
        at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)
        at java.util.ResourceBundle.getBundle(ResourceBundle.java:724)
        at org.test.util.RBLoader.loadResourceBundle(RBLoader.java:17)
        at org.apache.jsp.index_jsp._jspService(index_jsp.java:68)


when I deploy the app using

asadmin .... deploy --libraries TestBundle.jar,RBLib.jar <path-to-web-app>

Thanks for shedding some light...

-Bernhard

P.S. I'm try this not just for fun but having a 3rd party app which does
work similar






-- 
IT-Consulting Bernhard Thalmayr
- Painstaking Minds -
83620 Vagen (Munich area)
Germany