我有一个Eclipse JSF示例,其中ExampleController类找不到Bundle.properties文件。这是用于创建JSF项目的动态Web项目快照,
这是项目文件结构的快照。您可以在properties文件夹中看到bundles文件,
这是类代码的快照。注意getBundle方法中的文件名,
@ManagedBean(name = "exampleController")
@RequestScoped
public class ExampleController {
private String exampleProperty;
* Creates a new instance of ExampleController
*/
public ExampleController() {
exampleProperty = "Used to instantiate the bean.";
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO,
ResourceBundle.getBundle("WebContent/properties/Bundle.properties").getString("ExampleMessage"), null);
FacesContext.getCurrentInstance().addMessage(null, facesMsg);
}
最后,这是我在tomcat服务器上运行代码时错误的快照,
我尝试了几种文件名组合,但是在服务器运行时继续出现找不到文件的错误。我想念什么?
最好的问候,史蒂夫·曼斯菲尔德
Try to play with the path. The "WebContent" in your path does not seem right. Usually the resource path gets resolved relatively to WEB-INF or current class-file location. You could also try to put your properties directory in several places, to see if it gets picked up in one of those. :)
Also if you could get your hands on where the built project is actually run from "physically" (if it is not from these very files) maybe you would find out the properties file does not get copied with your other files. (Do you have Deployment Assembly in your Project settings? If so, check it out.)
UPDATE: If you simply need to open a properties file, check this one out: getResourceAsStream() is always returning null ...I don't know if your folder is special in some way tho.
多数情况下,当Tomcat在Eclipse中开始出现异常行为时,我发现Deployment Assembly已完成。(发生在Mavenized项目中。看来Eclipse和m2eclipse并不是最好的朋友。)
这种情况适合这样的情况:“当部署到生产服务器时工作,而不是从Eclipse中运行时工作。”
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句