How to prevent Eclipse from cleaning the bin folder for every build?

11,637

Solution 1

I can't say exactly why it does it, but probably that's just how Eclipse does the build: empty the "output folder" and start compiling.

That said, if you put your files into a source folder, then Eclipse will simply copy the files over to bin on every build and they won't disappear. It will do this to any file it doesn't know how to compile, e.g. .xml, .xsd, .png, etc.

Solution 2

Go to Options -> Java-> Compiler -> Building and uncheck Scrub output folders when cleaning projects.

That did the trick for me. In my project, I have an Ant task that adds a few configuration resources to the bin folder to include them in the classpath, without having them in src

Solution 3

You can consider using a maven style project and add the resources to the resources folder.

Here is a link to maven directory layout.

What kind of project you are using in eclipse. You can turn off build automatically feature in the Project menu. Which would stop eclipse from cleaning up projects automatically.

Share:
11,637
zw324
Author by

zw324

Ex Computer Science Student at NYU "The sleeper must awaken."

Updated on June 20, 2022

Comments

  • zw324
    zw324 almost 2 years

    I am now doing a project using Eclipse, and I have some resource files (e.g., image, text) saved in the bin folder, and these files are needed by the program.

    However, with every build, Eclipse would try to clean up the folder, then rebuild the project. When cleaning, it deletes the resource files in the folder. Is there anyway to stop Eclipse from doing this?

    I know I could change the location of the files, but I am also curious why Eclipse would do this, and could this be prevented from happening.

    Thanks!

  • zw324
    zw324 almost 13 years
    I found that Eclipse is copying my files, but not under the specific package folder but to the bin folder, which caused an error in the path. Could you give me some advices? Thanks!
  • Jesse Webb
    Jesse Webb almost 13 years
    If not using Maven, this is the correct solution. Put your files in the same directory as your source and Eclipse should put it in the bin directory every build for you.
  • meriton
    meriton almost 13 years
    It's worth noting that which resources eclipse copies from src to bin is configurable in Project -> Properties -> Java Build Path -> Source -> (name of source folder) -> Included and Excluded.
  • Rodney Gitzel
    Rodney Gitzel almost 13 years
    @ziyao, what kind of "error in the path" are you getting? Eclipse will copy the exact directory structure of your source folders(s) into the project's output folder. As @meriton notes, you might need to change their locations.
  • jr.
    jr. about 7 years
    This answer worked for me. As a word of warning, scrubbing can be configured at both the workspace (under Window > Preferences) and project (under Project > Properties) levels.
  • Paul Bellora
    Paul Bellora almost 6 years
    This didn't prevent my Eclipse (Oxygen.3a) from wiping out my target/generated-sources/protobuf/java.