63

I am trying to map my Visual Studio experience onto Eclipse. Right now, I wish to add a file existing somewhere on the file system into a project in Eclipse. I expect it to be copied to the project source folder.

Currently, I see only one way - switch to the windows explorer (total commander, in my case) and copy the file myself, after which to refresh the project.

Can I do the same without leaving the Eclipse IDE?

Thanks.

2
  • 2
    while it is leaving eclipse, you can also just drag the file out of the windows explorer and drop it into the Package Explorer as well. Nov 24, 2011 at 15:20
  • 4
    The interface is NOT intuitive at all. +1 for at least bringing this to the attention of the developers.
    – tarabyte
    Jan 18, 2015 at 3:09

9 Answers 9

74

I had the same problem, but found yet another solution.

Let me state my problem so that we're sure we're talking about the same thing.

I had a file in a directory where a bunch of code files were and some of the files in that directory were shown as "in my project" and some of the files were missing. I wanted the missing files to appear in my project.

I simply selected the folder in my project and pressed 'F5' or right-clicked and selected 'refresh' and the files appeared in my project. It looks like that is the intended way of doing this.

3
  • This is not the case described in the question.
    – mark
    Feb 27, 2014 at 14:44
  • 16
    @mark, While this wasn't exactly the question asked, this answer is still very useful for people that did have this issue and found this question while searching.
    – swbandit
    Jul 23, 2014 at 13:29
  • This is only a minor fix. It's not auto-built on a alt+s; you have to hit F5 instead. Nov 29, 2014 at 5:54
43

File->Import->General->File System should do it. There you can select the file(s) from some file system folder to your project (into folder).

6
  • 7
    this is not the same as "Add existing" in Visual Studio, as it will simply add it to the project definition, in eclipse, this trys to copy files Jan 7, 2013 at 20:56
  • 5
    @Keith the advanced tab in this dialog lets you link to files without copying.
    – Tod
    Nov 14, 2013 at 1:14
  • 11
    This doesn't work when the file is already where you want it to be. (This happened to me when some eclipse project file didn't save properly- the file was there but not in the project) Sep 9, 2014 at 22:51
  • 2
    Do any of you know why the "Next >" button would be grayed out after these steps? I've tried selecting all variations of things I could find in the "Import" dialog. Sep 16, 2014 at 21:40
  • 3
    Yes, I can’t figure out how to get Eclipse to realize that a source file that is already in the right place in the project (was created using IntelliJ IDEA) should be part of the project. This should not be so hard! Apr 24, 2016 at 0:24
12

Even easier. Just drag and drop the file from explorer into the correct package in Eclipse. It will ask you if you want to copy or link the file(s).

1
  • 1
    Brilliant answer! Drag and drop is the easiest way to achieve this.
    – Alexey
    Oct 22, 2019 at 4:07
5

I am a newbie to Eclipse Luna (the 64 bit latest version on Windows 7) but this worked for me:

  1. Copy the preexisting source files you which add to your project.
  2. In Project Explorer, right click your project and select New > File
  3. In the "New File" dialog box, your project's name / folder should be displayed as the parent folder for your new (existing) source file.
  4. Click on the "Advanced" button at the bottom of the "New File" dialog box.
  5. Check the "Link to file in the file system" checkbox.
  6. Click the "Browse" and browse to your preexisting source.
  7. Click the "Finish" button at the bottom of the dialog box.
1
  • This works fine for individual files, but you can't select multiple files, unfortunately
    – ardila
    May 28, 2016 at 12:23
3

In my case, I had to:

  1. right-click the project's name
  2. choose "Close Project"
  3. right-click the (now closed) project's name again
  4. choose "Open Project"

Refreshing didn't work for me. :(

Hopefully this helps someone else...

2
  • Wow! Thank you. I work on two machines and I overwrite the whole project tree to move from one machine to the other. (I know this is not ideal!) Sometimes, a source file drops out of the project (I don't know why) and errors appear. I know also this is a different situation possibly from the OP. However, your answer, @thargenediad, is a godsend: thank you very much!!
    – koan911
    Jun 4, 2015 at 10:51
  • You're welcome, @koan911! I'm glad my experience could help someone else. 😃 Jun 5, 2015 at 13:34
2

Just found the quickest way to add files:

  1. Copy-paste your file into your project disk directory using your file browser.

  2. In Eclipse project browser select your project.

  3. Click [right mouse button]->Refresh (or press F5 on Windows machine).

Voila

(worked on Neon-4.6.2)

0

I just got this to work. YMMV

I don't suppose it has to be there, but I put my file, xyz.cpp, into my project's source directory. My project has a source subdir named src, as in ProjName/src.

Right Click on project name (my project was open and the only one open). NEW->FILE. Put in the filename, xyz.cpp. Click OK or press enter.

The file will open in the editor and complain that it is empty. Close it WITHOUT SAVING.

Reopen the file. It now has its contents.

1
  • In your case you should be able to just hit F5 ( or right click on the project and select Refresh). The OP didn't want to copy the file manually.
    – Tod
    Nov 14, 2013 at 1:11
0

It turns out that just simply dragging the files into the src folder would work!

0
0

Right-click on the file after you have copied it into the project directory. Select Properties... in the left hand pane select C/C++ Build. There will be a checkbox "Exclude resource from build" uncheck that check box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.