Today is the second time I’ve been stumped by this problem.  Since I’ve solved it once before and couldn’t for the life of me remember how, I thought I’d better write down the solution so I’ll have it handy next time my Eclipse loses this setting.

Problem:

I have some integration JUnit tests that build XML and then compare the results to an XML file (of expected results) that I store in the same package as the test.  Sometimes my Eclipse decides that it cannot find this file and I when I run the test I get the error “Classpath resource not found: something.xml”.  I have also received this error when attempting to startup the Tomcat server and the application relies on configuration XML files being in the classpath, like hibernate.cfg.xml.

Source of Problem:

Eclipse is not outputting XML files to the build directory.  If you are having the same problem, take a look and see if yours are missing.

Solution:

Eclipse probably thinks you don’t want it to write the XML files to the build directory.  To instruct it that you do indeed need these files in the build directory, follow these steps:

  • Open the project properties dialog
  • Go to Java Compiler -> Building
  • If not already enabled, check “Enable project specific settings”
  • Look at the “filtered resources” field, ensure that *.xml is not in the list
  • Apply -> Ok

Eclipse will rebuild your project and you should be good to go.