java.util.MissingResourceException en el paquete de recursos

Hello All, I am creating a ResourceBundle to load the property files. My file structure looks like

| ---Main

   |
    ----ResourceBundleLoad.java

| --Resource

   |
    --- resourcebundle.properties

In normal when i put main class and the property file in same package means it retrieves all the property file values. If i separate both files means it's not working. It throws java.util.MissingResourceException exception.

Mi codigo es

 private static final String BUNDLE_NAME = "ExternalizedLogMessages";
 private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

Please suggest me how to solve this problem

preguntado el 24 de agosto de 12 a las 08:08

1 Respuestas

I achieve this by using the class loader. the source is

 private static URLClassLoader resourceLoader= null;

/**
 * Initialize class loader.
 */
static{
    ClassLoader currentThreadClassLoader
     = Thread.currentThread().getContextClassLoader();

    //assuming that current path is the project directory
    try {
        resourceLoader
         = new URLClassLoader(new URL[]{new File(".").toURI().toURL()},
                              currentThreadClassLoader);
    } catch (MalformedURLException e) {
        logger.error(e);
    }   
}

/**
 * Properties bundle name.
 */
private static final String BUNDLE_NAME = "resource.ExternalizedLogMessages"; //$NON-NLS-1$

/**
 * Resource bundle object.
 */
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
        .getBundle(BUNDLE_NAME,Locale.US,resourceLoader);

Respondido 24 ago 12, 10:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.