Is there an equivalent of "Add existing file" (to project) in Eclipse?

Eclipse

Eclipse Problem Overview


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.

Eclipse Solutions


Solution 1 - Eclipse

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.

Solution 2 - Eclipse

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).

Solution 3 - Eclipse

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).

Solution 4 - Eclipse

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.

Solution 5 - Eclipse

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...

Solution 6 - Eclipse

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)

Solution 7 - Eclipse

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.

Solution 8 - Eclipse

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

Solution 9 - Eclipse

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmarkView Question on Stackoverflow
Solution 1 - EclipsePete PView Answer on Stackoverflow
Solution 2 - EclipseUku LoskitView Answer on Stackoverflow
Solution 3 - EclipseClive PatersonView Answer on Stackoverflow
Solution 4 - Eclipseuser1260045View Answer on Stackoverflow
Solution 5 - EclipsethargenediadView Answer on Stackoverflow
Solution 6 - EclipseoopsView Answer on Stackoverflow
Solution 7 - EclipseWes MillerView Answer on Stackoverflow
Solution 8 - EclipseJiahui GuoView Answer on Stackoverflow
Solution 9 - EclipseSteve PreissigView Answer on Stackoverflow