[英].MissingResourceException: Can't find bundle for base name
我正在使用名为jnca的库来捕获从路由器发送的netflow udp数据包。
当它被导入到IntellijIDea中的新项目时,它可以工作。
在maven项目中使用它时,它不起作用并给出此异常。
例外:
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
没有包命名问题。
问题在于此代码段
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.properties文件包含在maven项目的资源文件夹中,它也无法正常工作
如何解决这个问题
谢谢
使用Maven时,属性文件应位于src / main / resources中,而不是src / main / java中(参见此处 )
因此,例如,如果faces-config.xml中有以下定义(用于在facelet页面中使用msgs变量):
<resource-bundle>
<base-name>i18n.PanneauPrincipal</base-name>
<var>msgs</var>
</resource-bundle>
或者,如果以编程方式加载资源文件:
ResourceBundle bundle = ResourceBundle.getBundle("i18n.PanneauPrincipal", locale);
然后PanneauPrincipal_en.properties文件应位于以下目录中:
src/main/resources/i18n
将.properties文件复制到根目录中的resources文件夹(不在包内)然后在您的代码中,当您要访问这些.properties文件时,不要提及任何包名称。 只有.properties文件的名称就足够了。 像这样:
resources = ResourceBundle.getBundle(myName, Locale.getDefault());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.