Java 找不到基本名称的包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2083159/
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 03:21:23  来源:igfitidea点击:

Can't find bundle for base name

javajfreechart

提问by Shane Castle

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. I've checked the CLASSPATH, still no go.

我试过创建 LocalizationBundle.properties 文件,但没有做到。我检查了 CLASSPATH,还是不行。

Any ideas?

有任何想法吗?

采纳答案by BalusC

java.util.MissingResourceException: Can't find bundle for base name
    org.jfree.chart.LocalizationBundle, locale en_US
java.util.MissingResourceException: Can't find bundle for base name
    org.jfree.chart.LocalizationBundle, locale 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 Sun's own tutorial about resourcebundlesfor more information.

另请参阅Sun 自己的关于资源的教程以获取更多信息。

But as this is actually a 3rd party managed properties file, you shouldn't create one yourself. It should be already available in the JFreeChart JAR file. 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 mighthave changed per JFreeChart version.

但由于这实际上是一个 3rd 方管理的属性文件,您不应该自己创建一个。它应该已经在 J​​FreeChart JAR 文件中可用。因此,请确保在运行时在类路径中提供它。还要确保您使用的是正确的版本,包树中属性文件的位置可能会随 JFreeChart 版本而改变。

When executing a JAR file, you can use the -cpargument to specify the classpath. E.g.:

执行 JAR 文件时,您可以使用-cp参数指定类路径。例如:

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

Alternatively you can specify the classpath as class-pathentry in the JAR's manifest file. You can use in there relative paths which are relative to the JAR file itself. Do notuse the %CLASSPATH%environment variable, it's ignoredby JAR's and everything else which aren't executed with java.exewithout-cp, -classpathand -jararguments.

或者,您可以将类路径指定为class-pathJAR 清单文件中的条目。您可以在其中使用相对于 JAR 文件本身的相对路径。千万不能使用%CLASSPATH%环境变量,它忽略了由JAR的和其他一切未与执行java.exe没有-cp-classpath-jar论据。

回答by trashgod

BalusC is right. Version 1.0.13 is current, but 1.0.9 appears to have the required bundles:

BalusC 是对的。版本 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

回答by Franky

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/

回答by mmdreza baqalpour

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. This did work for me .

如果您使用的是 IntelliJ IDE,只需右键单击资源包并转到新建,然后选择 Resource Boundle,它会自动为您创建一个 .properties 文件。这对我有用。