简体   繁体   English

在Eclipse中找不到文件

[英]Can't find file in Eclipse

I have an eclipse JSF example where the ExampleController class cannot find the Bundle.properties file. 我有一个Eclipse JSF示例,其中ExampleController类找不到Bundle.properties文件。 Here is the dynamic web project snapshot that was used to create the JSF project, 这是用于创建JSF项目的动态Web项目快照,

动态网络项目

Here is a snapshot of the project file structure. 这是项目文件结构的快照。 You can see the bundles file in properties folder, 您可以在properties文件夹中看到bundles文件,

项目文件结构

Here is a snapshot of the class code. 这是类代码的快照。 Notice the file name in the getBundle methode, 注意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);
}

Finally, here is a snapshot of the error when I run the code against the tomcat server, 最后,这是我在tomcat服务器上运行代码时错误的快照,

运行时Tomcat服务器错误

I have tried several combinations of file names but continue to get file not found errors when the server runs. 我尝试了几种文件名组合,但是在服务器运行时继续出现找不到文件的错误。 What am I missing? 我想念什么?

Best Regards, Steve Mansfield 最好的问候,史蒂夫·曼斯菲尔德

Try to play with the path. 尝试玩这条路。 The "WebContent" in your path does not seem right. 您路径中的“ WebContent”似乎不正确。 Usually the resource path gets resolved relatively to WEB-INF or current class-file location. 通常,资源路径是相对于WEB-INF或当前类文件位置来解析的。 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.) (您的Project设置中是否有Deployment Assembly?如果是,请签出。)

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. 更新:如果您只需要打开一个属性文件,请检查此属性: getResourceAsStream()始终返回null ...我不知道您的文件夹在某种程度上是否特殊。

Most often when Tomcat starts acting weirdly in Eclipse I find out that Deployment Assembly is f****d up. 多数情况下,当Tomcat在Eclipse中开始出现异常行为时,我发现Deployment Assembly已完成。 (Happens with Mavenized projects. Eclipse and m2eclipse aren't the best friends it seems.) (发生在Mavenized项目中。Eclipse和m2eclipse似乎并不是最好的朋友。)
Such situation fits the scenario "works when deployed to production server, does not when run from within Eclipse." 这种情况适合以下情形:“当部署到生产服务器时可以工作,而不能在Eclipse中运行则不能。”

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

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