1

I read (and sometimes write in) a .txt file in my java project and I'd like it to be copied in the eclipse output folder called "bin".

Can eclipse do it while compiling ?

My project is like :

  • Project
    • Bin
      • blabla.class
      • ...
    • Src
      • blabla.java
      • ...
    • MyFile.txt

Thanks !

  • 1
    [duplicate](http://stackoverflow.com/questions/5607723/copying-data-files-upon-build-in-java-eclipse) – hgoz Feb 10 '13 at 00:52

2 Answers2

1

I think you need to actually move the text file to a sub-directory - something like "resources" and add that "resources" directory as a source directory to the project - Project/Properties/Java Build Path/Source/Add Folder. That doesn't mean that everything in a source folder has to be compilable.

I don't think that you would have another option, because if you would add the root directory as source folder, eclipse would complain, that it cannot nest source folders. So you need an additional (re-)source folder here.

michael_s
  • 2,515
  • 18
  • 24
  • I tried it but it doesn't work. Should I check the box "Allow output folders for source folders" ? Because when I check it, and click "OK", and then re-open the Project Properties window, it stays unchecked ! I've googled it and it seems to be an unresolved bug of eclipse. – Etienne Callies Feb 10 '13 at 13:41
  • No, that just means, that the output (class-files) are copied to the source folders AFAIK. So, that actually didn't work out? Create a subdirectory "Res" (by your naming convention), move the text-file to "Res" and then add the "Res" directory to sources in the project settings? Don't forget to press F5 or refresh in the browser tree, if you moved the file manually. Then afterwards the text file should be copied to bin - after a clean build at least - doesn't it? – michael_s Feb 10 '13 at 13:53
  • Alternatively - I just saw that - you can create a new "source folder" in the project directly with Ctrl-N – michael_s Feb 10 '13 at 13:56
  • I am sorry but it definitely doesn't work. I currently use Eclipse Juno JavaEE Editor. I am gonna try with another version of eclipse... – Etienne Callies Feb 10 '13 at 14:20
1

The solution is :

use Eclipse Classic 4.2.1

click on "add project 'YourProjectName' folder to build path" while creating a new project (in Source tab)

Doing the right Include/Eclude stuff to select which files you want to copy

Vikdor
  • 23,934
  • 10
  • 61
  • 84