简体   繁体   English

找不到基本名称的包

[英]Can't find bundle for base name

I'm using a library that has a dependency on jfreechart (v 1.0.9).我正在使用依赖于 jfreechart (v 1.0.9) 的库。

When I try to run the .jar, I get:当我尝试运行 .jar 时,我得到:

java.util.MissingResourceException: Can't find bundle for base name
        org.jfree.chart.LocalizationBundle, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException
        (ResourceBundle.java:1521)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1260)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:962)

I've tried creating a LocalizationBundle.properties file, but that didnt do it.我试过创建 LocalizationBundle.properties 文件,但没有做到。 I've checked the CLASSPATH, still no go.我检查了 CLASSPATH,还是不行。

Any ideas?有什么想法吗?

java.util.MissingResourceException: Can't find bundle for base name java.util.MissingResourceException:找不到基本名称的包\n    org.jfree.chart.LocalizationBundle, locale en_US org.jfree.chart.LocalizationBundle,语言环境 en_US

To the point, the exception message tells in detail that you need to have either of the following files in the classpath:就这一点而言,异常消息详细说明您需要在类路径中具有以下任一文件:

/org/jfree/chart/LocalizationBundle.properties

or

/org/jfree/chart/LocalizationBundle_en.properties

or

/org/jfree/chart/LocalizationBundle_en_US.properties

Also see the official Java tutorial about resourcebundles for more information.另请参阅有关资源的官方 Java 教程以获取更多信息。

But as this is actually a 3rd party managed properties file, you shouldn't create one yourself.但由于这实际上是一个 3rd 方管理的属性文件,您不应该自己创建一个。 It should be already available in the JFreeChart JAR file.它应该已经在 J​​FreeChart JAR 文件中可用。 So ensure that you have it available in the classpath during runtime.因此,请确保在运行时在类路径中提供它。 Also ensure that you're using the right version, the location of the propertiesfile inside the package tree might have changed per JFreeChart version.还要确保您使用的是正确的版本,包树中属性文件的位置可能会随 JFreeChart 版本而改变。

When executing a JAR file, you can use the -cp argument to specify the classpath.执行 JAR 文件时,您可以使用-cp参数来指定类路径。 Eg:例如:

java -jar -cp c:/path/to/jfreechart.jar yourfile.jar

Alternatively you can specify the classpath as class-path entry in the JAR's manifest file.或者,您可以将类路径指定为 JAR 清单文件中的class-path条目。 You can use in there relative paths which are relative to the JAR file itself.您可以在其中使用相对于 JAR 文件本身的相对路径。 Do not use the %CLASSPATH% environment variable, it's ignored by JAR's and everything else which aren't executed with java.exe without -cp , -classpath and -jar arguments.不要使用%CLASSPATH%环境变量,它是由JAR的和其他一切未与执行忽略java.exe没有-cp-classpath-jar参数。

BalusC is right. BalusC 是对的。 Version 1.0.13 is current, but 1.0.9 appears to have the required bundles:版本 1.0.13 是最新的,但 1.0.9 似乎具有所需的包:

$ jar tf lib/jfreechart-1.0.9.jar | grep LocalizationBundle.properties 
org/jfree/chart/LocalizationBundle.properties
org/jfree/chart/editor/LocalizationBundle.properties
org/jfree/chart/plot/LocalizationBundle.properties

If you are using IntelliJ IDE just right click on resources package and go to new and then select Resource Boundle it automatically create a .properties file for you.如果您使用的是 IntelliJ IDE,只需右键单击资源包并转到新建,然后选择 Resource Boundle,它会自动为您创建一个 .properties 文件。 This did work for me .这对我有用。

将 .properties 文件放在与 com 相同级别的 src/ 文件夹下解决了问题。

When you create an initialization of the ResourceBundle, you can do this way also.当您创建 ResourceBundle 的初始化时,您也可以这样做。

For testing and development I have created a properties file under \\src with the name prp.properties.为了测试和开发,我在 \\src 下创建了一个名为 prp.properties 的属性文件。

Use this way:使用这种方式:

ResourceBundle rb = ResourceBundle.getBundle("prp");

Naming convention and stuff:命名约定和东西:

http://192.9.162.55/developer/technicalArticles/Intl/ResourceBundles/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM