mark
mark

Reputation: 62746

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

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.

Upvotes: 63

Views: 81305

Answers (9)

Steve Preissig
Steve Preissig

Reputation: 1

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.

Upvotes: 0

oops
oops

Reputation: 31

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)

Upvotes: 3

user1260045
user1260045

Reputation: 51

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.

Upvotes: 5

Jiahui Guo
Jiahui Guo

Reputation: 135

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

Upvotes: 0

thargenediad
thargenediad

Reputation: 395

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

Upvotes: 3

Pete P
Pete P

Reputation: 1108

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.

Upvotes: 77

Clive Paterson
Clive Paterson

Reputation: 789

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

Upvotes: 14

Wes Miller
Wes Miller

Reputation: 2241

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.

Upvotes: 0

Uku Loskit
Uku Loskit

Reputation: 42040

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

Upvotes: 43

Related Questions