java 程序未找到 JasperReports 资源包(.properties 文件)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4684679/
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
Program not finding JasperReports resource bundle (.properties file)
提问by Sean
I'm trying to use JasperReports in my JSF 2.0 application. I'm using NetBeans 6.9.1, mojarra 2.0.3, and PrimeFaces 2.2.RC2 as well. I've developed a trial report in iReport 3.7.6. I've changed one static label to a text field getting is value from a resource bundle/.properties file. The report runs as expected from iReport, but when I try to run it from my program I'm getting the following error:
我正在尝试在我的 JSF 2.0 应用程序中使用 JasperReports。我也在使用 NetBeans 6.9.1、mojarra 2.0.3 和 PrimeFaces 2.2.RC2。我已经在 iReport 3.7.6 中开发了一份试用报告。我已将一个静态标签更改为文本字段,从资源包/.properties 文件中获取值。该报告按预期从 iReport 运行,但是当我尝试从我的程序运行它时,出现以下错误:
SEVERE: javax.faces.FacesException: #{userReportBean.runReport}: java.util.MissingResourceException: Can't find bundle for base name Bundle, locale en_US
The report runs fine without reference to the bundle. Is my only solution to make the static labels parameters and pass them in at the time the report is run? Or is there a way to tell the report where to find the .properties file when the report isn't run from iReport?
报告运行良好,无需参考包。我唯一的解决方案是制作静态标签参数并在运行报告时将它们传递进来吗?或者,当报告不是从 iReport 运行时,有没有办法告诉报告在哪里可以找到 .properties 文件?
采纳答案by BalusC
This means that it cannot find any of the files Bundle_en_US.properties
, Bundle_en.properties
or Bundle.properties
in the classpath. You need to place it in the classpath which JasperReports has access to.
这意味着它找不到任何文件Bundle_en_US.properties
,Bundle_en.properties
或Bundle.properties
在类路径中。您需要将它放在 JasperReports 可以访问的类路径中。
Note that when you've actually placed them inside a package, then you need to specify that in the basename as well. E.g. com.example.Bundle
for the case that they're actually placed in a package named com.example
.
请注意,当您实际将它们放入包中时,您还需要在基本名称中指定它。例如,com.example.Bundle
对于它们实际上放置在名为com.example
.
回答by Diego Pino
You have to place the bundle in the same folder where you have your .jrxml file. If your reports is named "myreport.jrxml", you need to create a folder called "myreport_Bundle".
您必须将包放在您拥有 .jrxml 文件的同一文件夹中。如果您的报告名为“myreport.jrxml”,您需要创建一个名为“myreport_Bundle”的文件夹。
Inside that folder places your properties file:
在该文件夹中放置您的属性文件:
- myreport.properties (default file)
- myreport_en_US.properties (american English)
- myreport_es_ES.properites (spanish from Spain)
- etc
- myreport.properties(默认文件)
- myreport_en_US.properties(美式英语)
- myreport_es_ES.properites(来自西班牙的西班牙语)
- 等等
You also need to set the properties "Resources Bundle" in your report (via iReport, for instance). The value of the property is the same as the name of the file, in this case, "myreport" (no need to add "_Bundle").
您还需要在报告中设置属性“Resources Bundle”(例如,通过 iReport)。该属性的值与文件名相同,在本例中为“myreport”(无需添加“_Bundle”)。