'How to access ResourceBundle from jar within a jar

Right now I have a library that works and access resources like follows:

//this is in MyLib.jar
class Helper {
static{
 ResourceBundle localResource = ResourceBundle.getBundle(ResourcesDef.Language_Path);
}

public static String getString(String res) {


            if (localResource != null) {
                try {
                    return localResource.getString(res);
                } catch (Exception ee) {
                    return "STRING-NOT-FOUND-FOR => " + res;
                }
            }
    return "STRING-NOT-FOUND-FOR => " + res;
}
}

this is my ResourceDef class:

//this is in MyLib.jar
public class ResourcesDef {
    public static String Language_Path = "mylib/resources/languages/langTable";


    //also tested with:
    //public static String Language_Path = "resources/languages/langTable"; //KO
    //public static String Language_Path = "langTable"; //KO

    /*
    * ....
    */
    public ResourcesDef() {
    }
}

My resources file in package mylib.resources.languages

#file: langTable.properties
who=World


//MyLib
import MyLib.Helper
class TestMain{
/**
 * library's test main
*/
public static void main (String[] args){
    system.out.println("TEST: "+Helper.getString("who") );
    }
}

And it's fine if I launch this "library" like
java -jar mylib.jar MyLib.TestMain I Got:
TEST: Hello World

But If I use this library whithin another project it fails

<!-- myproject pom.xml -->

...
<!-- Including the library as jar -->
<dependency>
    <groupId>com.dds</groupId>
    <artifactId>mylib</artifactId>
    <version>0.0.1</version>    
</dependency>

I use the library

//MyProject
import MyLib.Helper
class Main{

public static void main (String[] args){
    system.out.println("MAIN Hello "+Helper.getString("who") );
    
    }
}

If I run
java -jar MyProject.jar MyProject.Main
I Got
MAIN: Hello STRING-NOT-FOUND-FOR => who



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source