Search code examples
javaeclipsebuildpath

should I exclude source folder from build path (in Eclipse)


I have some java projects that use external files as input. I usually store the files in the package directory under a folder which i name "resources". My question now is: should i exclude these folders from the build path? I though that they have to be included, but my programm still works even if they are excluded. Also the logo of the folder changes when i include/exclude the folder. Please see the attached picture. This isnt a very big issue but i was just curious. Thanks for every input on that.

eclipse package explorer example


Solution

  • Every file included in the source folders is processed:

    • Source files (.java) are compiled and the result classes are written out to the target folder (bin by default).
    • Non-source files (.properties, .txt, .xml, etc) are just copied as they are to the target folder.

    Then, at execution time, only files from the target folder can be accessed by the program. Why? Because only the target folder shall be packaged into a Jar and eventually distributed. So you must not rely into the temporary circumstance that your program is reading non-source directories when executing from your IDE. Everything that shall be distributed must be into source directories.