0

I am encountering an issue when trying to load a resource.

java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("Bundle");

My file is correctly named Bundle_en_US.properties in the src folder.

While I am aware of this solution (and many others), my case is different because my Java program runs fine from Eclipse but the error below is triggered when ran from an executable jar file.

Exception in thread "AWT-EventQueue-0" java.util.MissingResourceException: Can't find bundle for base name Bundle, locale en_US

                at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)

                at java.util.ResourceBundle.getBundleImpl(Unknown Source)

                at java.util.ResourceBundle.getBundle(Unknown Source)

I am using: Windows 10, Eclipse Photon, JDK 8 and JDK 10, JRE 8 and JRE 10

And I can see all my *.properties files in the jar file when opening with an archive manager : enter image description here

Frederic
  • 2,015
  • 4
  • 20
  • 37
  • You've manually checked that it's there in the .jar file? – nitind Jul 24 '18 at 18:29
  • Good question but yes, I've opened the jar file with 7Zip and I can see the *.properties files under src – Frederic Jul 24 '18 at 18:29
  • Your .jar file has a "src" folder? That doesn't sound right. At the least it's not part of the bundle name you're passing in. – nitind Jul 24 '18 at 18:35
  • No, I don't pass the src in the bundle name (see my code in my question). But my jar has an src folder right at the root at the jar, is that not correct ? – Frederic Jul 24 '18 at 18:36
  • Are the properties files in the root folder of the jar? – nitind Jul 24 '18 at 18:43
  • Like I mentioned i my question, they're in the src folder – Frederic Jul 24 '18 at 21:04
  • What are the full paths of the class file and properties file when they're in the jar? You might want to debug and step through the loading in Eclipse so you understand where it's expecting the properties file to be. – nitind Jul 25 '18 at 05:12
  • Sure, I could debug and I might but since it's working when launching from Eclipse, it will be hard to see a potential clue as it will work fine – Frederic Jul 25 '18 at 15:07

1 Answers1

1

I just found the solution to my own issue. The reason was that in the .classpath file, only the .java files were outputted. Hence, my properties files were outputted in a different directory and were not found by the resourceLoader.

Original .classpath entry :

<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">

Resolved by modifying the line entry to :

<classpathentry kind="src" output="target/classes" path="src">
Frederic
  • 2,015
  • 4
  • 20
  • 37