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.

mark
  • 59,016
  • 79
  • 296
  • 580
  • 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. – Paul Webster Nov 24 '11 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 '15 at 03:09

9 Answers9

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.

Pete P
  • 1,048
  • 7
  • 12
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).

Uku Loskit
  • 40,868
  • 9
  • 92
  • 93
  • 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 – Keith Nicholas Jan 07 '13 at 20:56
  • 5
    @Keith the advanced tab in this dialog lets you link to files without copying. – Tod Nov 14 '13 at 01: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) – Frank Schwieterman Sep 09 '14 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. – JustBeingHelpful Sep 16 '14 at 21:40
  • Turns out that I had an existing maven project along side my new empty project with a build error, but no files. I couldn't see it because the "Project Explorer" wasn't showing. I added it by going to "Window" (menu) > "Show View" > "Project Explorer". Then I right clicked the project to delete it, so the error would go away. Then within that dialog, I had to click the browse button, and then it finally showed my valid projects. I selected one, and the "Next >" button then showed up. – JustBeingHelpful Sep 16 '14 at 21:56
  • 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! – James Elliott Apr 24 '16 at 00: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).

Clive Paterson
  • 749
  • 8
  • 9
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.
Prudhvi
  • 2,276
  • 7
  • 34
  • 54
user1260045
  • 51
  • 1
  • 1
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...

thargenediad
  • 388
  • 1
  • 3
  • 10
  • 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 04 '15 at 10:51
  • You're welcome, @koan911! I'm glad my experience could help someone else. – thargenediad Jun 05 '15 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)

oops
  • 21
  • 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.

Wes Miller
  • 2,191
  • 2
  • 38
  • 64
  • 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 '13 at 01:11
0

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

Jiahui Guo
  • 135
  • 2
  • 10
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.