I created a standard Java Project in Eclipse, placed a XML file in the src
folder with the intent to grab it by Class#getResourceAsStream()
, and I was baffled when Eclipse can't seem to locate the XML file in the classpath. After a little test it turns out that files with other extensions are perfectly located.
我在Eclipse中创建了一个标准的Java项目,在src文件夹中放置了一个XML文件,目的是通过Class#getResourceAsStream()来获取它,当Eclipse无法在类路径中找到XML文件时,我感到很困惑。经过一点点测试后发现,带有其他扩展名的文件位置非常合适。
Here's a screen which says it all:
这是一个全部说明的屏幕:
It prints null
for the /test.xml
resource. The Class#getResourceAsStream()
obviously doesn't make any difference.
它为/test.xml资源打印null。 Class#getResourceAsStream()显然没有任何区别。
I checked the project's /bin
folder and the XML file is indeed not there. I've checked all settings to see if there isn't some filter to exclude certain files from ending up in the /bin
folder during the build, but all in vain.
我检查了项目的/ bin文件夹,确实没有XML文件。我已经检查了所有设置,看看是否没有一些过滤器可以在构建过程中排除某些文件在/ bin文件夹中结束,但都是徒劳的。
How is this caused and how can I solve it? I'm using Eclipse Galileo with build id 20090920-1017.
这是怎么造成的,如何解决?我正在使用带有内部版本号20090920-1017的Eclipse Galileo。
1 个解决方案
#1
13
This sounds vaguely familiar. Go to Prefs -> Java -> Compiler -> Building -> Output Folder, and make sure the "filtered resources" field doesn't include XML files. Also check the project-specific preferences.
这听起来很模糊。转到Prefs - > Java - > Compiler - > Building - > Output Folder,并确保“filtered resources”字段不包含XML文件。还要检查项目特定的首选项。
I seem to recall that older versions of Eclipse had this in by default, but I'm not sure why it'd happen with a newer version.
我似乎记得Eclipse的旧版本默认使用此功能,但我不确定为什么它会在更新的版本中发生。
#1
13
This sounds vaguely familiar. Go to Prefs -> Java -> Compiler -> Building -> Output Folder, and make sure the "filtered resources" field doesn't include XML files. Also check the project-specific preferences.
这听起来很模糊。转到Prefs - > Java - > Compiler - > Building - > Output Folder,并确保“filtered resources”字段不包含XML文件。还要检查项目特定的首选项。
I seem to recall that older versions of Eclipse had this in by default, but I'm not sure why it'd happen with a newer version.
我似乎记得Eclipse的旧版本默认使用此功能,但我不确定为什么它会在更新的版本中发生。