在 Eclipse 中找不到文件
Can't find file in Eclipse
我有一个 Eclipse JSF 示例,其中 ExampleController class 找不到 Bundle.properties 文件。这是用于创建 JSF 项目的动态 Web 项目快照,
这是项目文件结构的快照。您可以在属性文件夹中看到捆绑文件,
这是 class 代码的快照。注意 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 服务器
的代码时的错误快照
我尝试了几种文件名组合,但在服务器 运行s 时继续出现文件未找到错误。我错过了什么?
此致,
史蒂夫·曼斯菲尔德
尝试玩转路径。您路径中的 "WebContent" 似乎不正确。
通常资源路径相对于 WEB-INF 或当前 class 文件位置得到解析。
您还可以尝试将您的属性目录放在多个位置,以查看它是否在其中一个位置被拾取。 :)
此外,如果您可以从 "physically" 中了解构建项目实际 运行 的位置(如果它不是来自这些文件),您可能会发现属性文件没有与您的其他文件一起复制。 (您的项目设置中是否有部署程序集?如果有,请查看。)
更新:如果您只需要打开一个属性文件,请查看以下文件:
getResourceAsStream() is always returning null
...我不知道您的文件夹在某些方面是否特别。
大多数情况下,当 Tomcat 开始在 Eclipse 中表现怪异时,我发现 Deployment Assembly 搞砸了。 (发生在 Mavenized 项目中。Eclipse 和 m2eclipse 看起来并不是最好的朋友。)
这种情况符合"works when deployed to production server, does not when run from within Eclipse."
的场景
我有一个 Eclipse JSF 示例,其中 ExampleController class 找不到 Bundle.properties 文件。这是用于创建 JSF 项目的动态 Web 项目快照,
这是项目文件结构的快照。您可以在属性文件夹中看到捆绑文件,
这是 class 代码的快照。注意 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 服务器
的代码时的错误快照我尝试了几种文件名组合,但在服务器 运行s 时继续出现文件未找到错误。我错过了什么?
此致, 史蒂夫·曼斯菲尔德
尝试玩转路径。您路径中的 "WebContent" 似乎不正确。 通常资源路径相对于 WEB-INF 或当前 class 文件位置得到解析。 您还可以尝试将您的属性目录放在多个位置,以查看它是否在其中一个位置被拾取。 :)
此外,如果您可以从 "physically" 中了解构建项目实际 运行 的位置(如果它不是来自这些文件),您可能会发现属性文件没有与您的其他文件一起复制。 (您的项目设置中是否有部署程序集?如果有,请查看。)
更新:如果您只需要打开一个属性文件,请查看以下文件: getResourceAsStream() is always returning null ...我不知道您的文件夹在某些方面是否特别。
大多数情况下,当 Tomcat 开始在 Eclipse 中表现怪异时,我发现 Deployment Assembly 搞砸了。 (发生在 Mavenized 项目中。Eclipse 和 m2eclipse 看起来并不是最好的朋友。)
这种情况符合"works when deployed to production server, does not when run from within Eclipse."