在 Eclipse 中是否有等效的“添加现有文件”(到项目)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8253861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:43:21  来源:igfitidea点击:

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

eclipse

提问by mark

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.

我正在尝试将我的 Visual Studio 体验映射到 Eclipse。现在,我希望将文件系统上某处存在的文件添加到 Eclipse 中的项目中。我希望它被复制到项目源文件夹。

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.

目前,我只看到一种方法 - 切换到 Windows 资源管理器(在我的情况下为总指挥官)并自己复制文件,然后刷新项目。

Can I do the same without leaving the Eclipse IDE?

我可以在不离开 Eclipse IDE 的情况下做同样的事情吗?

Thanks.

谢谢。

采纳答案by Uku Loskit

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

File->Import->General->File System应该这样做。在那里,您可以从某个文件系统文件夹中选择文件到您的项目 ( into folder)。

回答by Pete P

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.

我只需选择项目中的文件夹并按“F5”或右键单击并选择“刷新”,文件就会出现在我的项目中。看起来这是这样做的预期方式。

回答by Clive Paterson

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

更容易。只需将文件从资源管理器拖放到 Eclipse 中的正确包中即可。它会询问您是否要复制或链接文件。

回答by user1260045

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

我是 Eclipse Luna(Windows 7 上的 64 位最新版本)的新手,但这对我有用:

  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. 复制您添加到项目中的预先存在的源文件。
  2. 在 Project Explorer 中,右键单击您的项目并选择New > File
  3. “新建文件”对话框中,您的项目名称/文件夹应显示为新(现有)源文件的父文件夹。
  4. 单击“新建文件”对话框底部的“高级”按钮。
  5. 选中“链接到文件系统中的文件”复选框。
  6. 单击“浏览”并浏览到您先前存在的源。
  7. 单击对话框底部的“完成”按钮。

回答by thargenediad

In my case, I had to:

就我而言,我不得不:

  1. right-clickthe project's name
  2. choose "Close Project"
  3. right-clickthe (now closed) project's name again
  4. choose "Open Project"
  1. 右键单击项目名称
  2. 选择“关闭项目
  3. 再次右键单击(现已关闭)项目的名称
  4. 选择“打开项目

Refreshing didn't work for me. :(

刷新对我不起作用。:(

Hopefully this helps someone else...

希望这对其他人有帮助...

回答by oops

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

  1. 使用文件浏览器将文件复制粘贴到项目磁盘目录中。

  2. 在 Eclipse 项目浏览器中选择您的项目。

  3. 单击 [鼠标右键]->刷新(或在 Windows 机器上按 F5)。

Voila

(worked on Neon-4.6.2)

(在 Neon-4.6.2 上工作)

回答by Jiahui Guo

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

事实证明,只需将文件拖入 src 文件夹即可!

回答by Wes Miller

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.

我不认为它必须在那里,但我将我的文件 xyz.cpp 放入我的项目的源目录中。我的项目有一个名为 src 的源子目录,如 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.

右键单击项目名称(我的项目是打开的,只有一个打开)。新建-> 文件。输入文件名 xyz.cpp。单击“确定”或按 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.

重新打开文件。现在有了它的内容。