Java .MissingResourceException: 找不到基本名称的包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21903691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 11:20:41  来源:igfitidea点击:

.MissingResourceException: Can't find bundle for base name

javamavenresourcebundle

提问by Asiri Liyana Arachchi

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

我正在使用名为 jnca 的库来捕获从路由器发送的 netflow udp 数据包。

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

当它导入到 IntellijIDea 中的新项目时,它就可以工作了。

JNCA

JNCA

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

打赌在 Maven 项目中使用它时它不起作用并给出此异常。

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

我的名字 = 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

我曾尝试更改资源的路径,但没有奏效。并尝试将该 netflow.properties 文件包含在 Maven 项目的资源文件夹中,但它也不起作用

How to fix this

如何解决这个问题

Thank you

谢谢

采纳答案by Pierre C

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

使用 Maven 时,属性文件应位于 src/main/resources 中,而不是 src/main/java 中(请参见 此处

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

因此,例如,如果您的 faces-config.xml 中有以下定义(用于在您的 facelet 页面中使用 msgs 变量):

    <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 :

然后 PanneauPrincipal_en.properties 文件应位于以下目录中:

    src/main/resources/i18n

回答by sakhoshdel

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:

将您的 .properties 文件复制到根目录中的资源文件夹(而不是包内)然后在您想要访问这些 .properties 文件时的代码中不要提及任何包名称。只需要 .properties 文件的名字就够了。像这样:

 resources = ResourceBundle.getBundle(myName, Locale.getDefault());