Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.MissingResourceException: Can't find bundle for base name

I'm using library called jnca to capture netflow udp packets sent from a router.

When it's imported in to a new project in IntellijIDea it works.

JNCA

Bet when that is used inside a maven project it doesn't work and gives this exception.

jnca

Exception:

java.util.MissingResourceException: Can't find bundle for base name org.wso2.event.adaptor.udp.jnca.etc.NetFlow, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1499)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:795)
at org.wso2.event.adaptor.udp.jnca.cai.utils.Resources.<init>(Resources.java:24)
at org.wso2.event.adaptor.udp.jnca.cai.flow.collector.Collector.<clinit>(Collector.java:51)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.wso2.event.adaptor.udp.jnca.cai.flow.collector.Run.<clinit>(Run.java:14)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
NetFlow.properties: Can't find bundle for base name org.wso2.event.adaptor.udp.jnca.etc.NetFlow, locale en_US

There is no package naming issues.

Problem is with this code segment

      try {

        resources = ResourceBundle.getBundle("org.wso2.event.adaptor.udp.jnca.etc." + myName, Locale
                                             .getDefault());
    } catch (MissingResourceException exc) {
        exc.printStackTrace();
        error(SuperString.exceptionMsg(exc.toString()));
    }

myName = Netflow

I have tried changing the path to the resource but it didn't work. And tried to include that netflow.properties file inside the maven project's resources folder it also didn't work

How to fix this

Thank you

like image 309
Asiri Liyana Arachchi Avatar asked Dec 12 '22 07:12

Asiri Liyana Arachchi


2 Answers

When using Maven, properties files should be located inside src/main/resources not in src/main/java (see here)

So, for instance, if you have the following definition in your faces-config.xml (for using the msgs variable in your facelet pages) :

    <resource-bundle>
        <base-name>i18n.PanneauPrincipal</base-name>
        <var>msgs</var>
    </resource-bundle>

Or if you load the resource files programmatically :

    ResourceBundle bundle = ResourceBundle.getBundle("i18n.PanneauPrincipal", locale);

Then the PanneauPrincipal_en.properties file should be located in the following directory :

    src/main/resources/i18n
like image 53
Pierre C Avatar answered Dec 13 '22 19:12

Pierre C


Copy your .properties files to the resources folder in the root (not inside packages) And then in your code when you want to access these .properties files don't mention any package name. just only the name of the .properties files in enough. like this:

 resources = ResourceBundle.getBundle(myName, Locale.getDefault());
like image 39
sakhoshdel Avatar answered Dec 13 '22 20:12

sakhoshdel