52

I'm using a library that has a dependency on JSF.

When I try to run my project, it show following exception massage..

java.util.MissingResourceException: Can't find bundle for base name /Bundle, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:705)

Any ideas ?

14 Answers14

71

The exception is telling that a Bundle_en_US.properties, or Bundle_en.properties, or at least Bundle.properties file is expected in the root of the classpath, but there is actually none.

Make sure that at least one of the mentioned files is present in the root of the classpath. Or, make sure that you provide the proper bundle name. For example, if the bundle files are actually been placed in the package com.example.i18n, then you need to pass com.example.i18n.Bundle as bundle name instead of Bundle.

In case you're using Eclipse "Dynamic Web Project", the classpath root is represented by src folder, there where all your Java packages are. In case you're using a Maven project, the classpath root for resource files is represented by src/main/resources folder.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    As also mentioned here, if you're on a Maven project manually create a new "resources" folder inside src/main/ and put all your resources inside it. Clean -> Build and run the project again resources will get picked up. – Dasun Nirmitha Jun 02 '20 at 15:40
13

maven-tomcat-plugin

If you start the Project using the maven-tomcat-plugin / maven-tomcat7-plugin, you must place the Bundle.properties, or even the Resource.properties in src/main/webapp/WEB-INF/classes. Dont ask why, its because how the plugin fake a tomcat.

Grim
  • 1,938
  • 10
  • 56
  • 123
  • 3
    after move the .properties files into WEB-INF/classes (even create another wrapper folder under it) it works. up vote and thanks! – lannyf Jan 17 '16 at 23:43
  • 1
    A quick thanks to Grim and lannyf, as their information helped me with a similar problem on Resin web server. I was working on a project where the properties file was stored along with the .jar files in `webapps/ROOT/WEB-INF/lib/`. There was nothing in `webapps/ROOT/WEB-INF/classes/`. When I tried copying this setup across to a new server, I got an error "Caught exception: Can't find base number for bundle X, locale en". However, when I created a symlink in `webapps/ROOT/WEB-INF/classes/` pointing to the .properties file in the `lib/` folder, it fixed the issue. Much appreciated! – Kitserve Aug 12 '20 at 06:19
8

If you are running the .java file in Eclipse you need to add the resource path in the build path . after that you will not see this error

harry
  • 81
  • 1
  • 1
6

In my case the problem was using the language tag "en_US" in Locale.forLanguageTag(..) instead of "en-US" - use a dash instead of underline!

Also use Locale.forLanguageTag("en-US") instead of new Locale("en_US") or new Locale("en_US") to define a language ("en") with a region ("US") - but new Locale("en") works.

electrobabe
  • 1,549
  • 18
  • 17
4

I had the same problemo, and balus solution fixed it.

For the record:

WEB-INF\faces-config is

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
    <application>
        <locale-config>
            <default-locale>en</default-locale>
        </locale-config>
        <message-bundle>
            Message
        </message-bundle>
    </application>
</faces-config>

And had Message.properties under WebContent\Resources (after mkyong's tutorial)

the pesky exception appeared even when i renamed the bundle to "Message_en_us" and "Message_en". Moving it to src\ worked.

Should someone post the missing piece to make bundles work under resources,it would be a beautiful thing.

demonz demonz
  • 641
  • 1
  • 15
  • 32
1

In my case I was dealing with SpringBoot project and I got the same exception.

Solution is made by adding env.properties file into classpath (i.e. src/main/resource folder). What was making the issue is that in log4j configuration there was property like

<Property name="basePath">${bundle:env:log.file.path}</Property>

milosdju
  • 783
  • 12
  • 27
1

In maven, folder resources, create the same package structure where the configuration files are located and copy them there

1

The Bundle.properties file must be in the directory of the .class files. If it is located in the src directory then you need to make sure to copy it to the bin (output) directory in the same package.

Alex Mandelias
  • 436
  • 5
  • 10
1

Bundle names have to be fully qualified, like if your bundle Bundle.properties is inside x.y.z package, then you have to write ResourceBundle.getBundle("x.y.z.Bundle");

0

I had the same problem using Netbeans. I went to the project folder and copied the properties file. I think clicked "build" and then "classes." I added the properties file in that folder. That solved my problem.

SedJ601
  • 12,173
  • 3
  • 41
  • 59
0

I use Eclipse (without Maven) so I place the .properties file in src folder that also contains the java source code, in order to have the .properties file in the classes folder after building the project. It works fine. Take a look at this post: https://www.mkyong.com/jsf2/cant-find-bundle-for-base-name-xxx-locale-en_us/

Hope this help you.

0

The problem must be that the resource-bunde > base-name attribute at the faces-config.xml file has a different path to your properties. This happened to me on the firstcup Java EE tutorial, I gave a different package name on then project creation and then Glassfish was unable to find the properties folder which is on "firstcup.web".

I hope it helps.

Mr. DMX
  • 653
  • 2
  • 9
  • 20
0

Make sure you didn't add the properties files in the wrong resources folder as there is one under 'Web Pages' and one under 'Other Sources/...'. They needed to be under 'Other Sources/...'.

Blue
  • 22,608
  • 7
  • 62
  • 92
0

I was able to resolve the issue, the resource was in my project directories but when the junit utility tries to load it, it was returning an error of MissingResourceException. And the reason was the resource was in the not on the classpath of the test class package so when I added the cfg/ folder to my classpath path entry in eclipse and set the output directory in the build conf to the same class package the issue was resolved.

When you try this approach just make sure, the classpath conf file shows the classpath entry of the resource directory (eg. cfg/)