java.util.MissingResourceException: Can't find bundle for base name resources.application, locale en
Asked Answered
C

5

7

My faces-config.xml likes below.

<?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>
    <message-bundle>resources.application</message-bundle>
    <locale-config>
        <default-locale>en</default-locale>
    </locale-config>
</application>

</faces-config>

Xhtml file

<f:loadBundle basename="resources.application" var="msg"/>

I am getting the below exception

javax.faces.view.facelets.TagAttributeException: //D:/12c_Workspace/VNPO/WebContent/login.xhtml @9,59 <f:loadBundle basename="resources.application"> Can't find bundle for base name resources.application, locale en
    at com.sun.faces.facelets.tag.jsf.core.LoadBundleHandler.apply(LoadBundleHandler.java:233)
    at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
    at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
    at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
    at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
    at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:338)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)
    at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3288)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2163)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2089)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1513)
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.util.MissingResourceException: Can't find bundle for base name resources.application, locale en
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:952)
    at com.sun.faces.facelets.tag.jsf.core.LoadBundleHandler.apply(LoadBundleHandler.java:227)

How is this caused and how can I solve it?

Canute answered 2/12, 2013 at 12:30 Comment(0)
T
10

Exception clearly says that you don't have a application_en.properties or at least application.properties file in the resources package in the runtime classpath.

That's really it. Just make sure you have one.


Unrelated to the concrete problem, I just want to warn that <message-bundle> and <f:loadBundle> are mutually exclusive. To learn about the difference, head to Internationalization in JSF, when to use message-bundle and resource-bundle?

Tennes answered 2/12, 2013 at 12:44 Comment(5)
Hi. I have "application.properties" file at "resources" folder.Canute
Package, not folder. A "folder" has no special meaning in Java while a "package" is a folder which actually ends up in runtime classpath (and usually contains Java classes, but can also contain properties files and such). It sounds like you got classpath/building/packaging concepts and/or project structure messed up. First of all, are you using Maven or so?Tennes
I am not using Maven, Sorry that was package like src/resourcesCanute
Well, apparently build went wrong. Either the build skipped .properties files, or the build hasn't run at all. Check build settings, clean, rebuild, redeploy, etc. To exclude one and other, let the build export a WAR file and then unzip it yourself to see if /WEB-INF/classes/resources/application.properties file is physically present. If not, then that totally explains the exception.Tennes
thanks Buddy. now it is got resolved . but I am getting one more issue while pointing the value from properties files.Canute
S
4

You need 2 things:

  1. To have your messages.properties file in your class-path. The safest bet is to put it under src/main/java/your/package/name
  2. Configure it in your faces-config.xml:

http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" version="2.2">

    <application>
        <resource-bundle>
            <base-name>your.package.name.messages</base-name>
            <var>i18n</var>
        </resource-bundle>
    </application>

</faces-config>

Note that you don't include .properties suffix in faces-config.xml

Segno answered 11/1, 2016 at 22:1 Comment(3)
Thing 1 is already answered. Thing 2 is already done by OP. How exactly does this post answer OP's concrete problem and/or add up to what's already mentioned/given?Tennes
My answer relates to the case when packages are being used (good practice). In his example he didn't specify it with package name in faces-config.xml Also you are suggesting to put in src/main/resources. I am suggesting to put in src/main/javaSegno
OP used package resources in src.Tennes
T
3

If you are using Maven you must to put the properties files in the folder src/main/resources not with the packages thar are in src/main/java

Tabina answered 5/10, 2016 at 17:17 Comment(0)
P
0

Here is what you can do:

  • Step I : Keep Maven files to install and use.

  • Step II: You need to set class path of Maven in Environment Variable

  • Step III: Install Maven with command mvn install on command prompt after reaching then /bin directory in Maven directory.

Now clean project and deploy Maven Project to run.

Prothorax answered 30/5, 2017 at 6:28 Comment(0)
D
-1

With Eclipse and Windows: you have to copy 2 files

  • xxxPROJECTxxx.properties

  • log4j.properties

here : C:\Eclipse\CONTENER\TOMCAT\apache-tomcat-7\lib

Danger answered 19/11, 2016 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.