如何将 *.java 文本文件导入 Eclipse 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19814436/
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-08-12 20:25:54  来源:igfitidea点击:

How do I import *.java text files into an Eclipse project?

javaeclipseimport

提问by dwwilson66

I'm finally biting the bullet and starting use Eclipse (Europa for now) instead of command-line java and Notepad. However, I've not really organized my projects apart from naming conventions (e.g., ProjAClassname1, ProjAClassname2, ProjAClassname3, etc) and they're all in my JRE java/bin directory. I have a directory full of *.java files that I want to start organizing into a brand new install of Eclipse.

我终于咬紧牙关开始使用 Eclipse(现在是 Europa)而不是命令行 java 和记事本。但是,除了命名约定(例如,ProjAClassname1、ProjAClassname2、ProjAClassname3 等)之外,我并没有真正组织我的项目,它们都在我的 JRE java/bin 目录中。我有一个包含 *.java 文件的目录,我想开始将其组织到全新的 Eclipse 安装中。

I've followed the instructions in the Eclipse help files, googled for a while and I've found some excellent Stack answers on importing JAR files, importing existingEclipse projects. However, none of these work. None of the resulting dialogs show a list of files to import/add; I think they assume that all my classes are contained in *.jar files instead of *.java files.

我已经按照 Eclipse 帮助文件中的说明进行了搜索,搜索了一段时间,我发现了一些关于导入 JAR 文件导入现有Eclipse 项目的优秀 Stack 答案。但是,这些都不起作用。结果对话框都没有显示要导入/添加的文件列表;我认为他们假设我所有的类都包含在 *.jar 文件而不是 *.java 文件中。

I created java\bin\ProjA\src and copied all my source code *.java; same results. The closest I got was creating a new project, then dragging and dropping the *.jave files from Explorer to Eclipse. The classes all showed up as part of the project, but I had the little red x indicating "out of sync with file system", and even though I found this, none of the solutions offered in that answer worked for me.

我创建了 java\bin\ProjA\src 并复制了我所有的源代码 *.java; 相同的结果。我得到的最接近的是创建一个新项目,然后将 *.jave 文件从资源管理器拖放到 Eclipse。这些类都作为项目的一部分出现,但我有一个小红 x 表示“与文件系统不同步”,即使我发现了这一点,该答案中提供的解决方案都没有对我有用。

Before I start creating new classes and cutting/pasting from Notepad, I wanted to know if there were any other ideas floating out there?

在我开始从记事本创建新类和剪切/粘贴之前,我想知道是否还有其他想法浮出水面?

采纳答案by Ankit Rustagi

You can add your java files by simply dragging them to eclipse, then try doing this

您可以通过简单地将它们拖到 eclipse 中来添加您的 java 文件,然后尝试执行此操作

Go to "Project" -> Clean

转到“项目”-> 清理

enter image description here

在此处输入图片说明

Then select all projects and click on Ok

然后选择所有项目并单击确定

回答by CompuChip

First of all, I would recommend using a newer version of Eclipse. The current version is Kepler (4.3, whereas Europa is 3.3) which means you are about seven releases behind.

首先,我建议使用较新版本的 Eclipse。当前版本是 Kepler(4.3,而 Europa 是 3.3),这意味着您大约落后七个版本。

More to the point, if you have a folder with all your Java files in them, you could use File -> Import and pull in all the files from a directory into the workspace.

更重要的是,如果您有一个包含所有 Java 文件的文件夹,您可以使用 File -> Import 并将目录中的所有文件拉入工作区。

回答by Amraddin Jamalli

To import your project to Eclipse that was coded in other editors such as Textpad and etc., simply open eclipse and make a new project, expand your project, and then go to your folder, take your .javafile and other packages and drag it on the source folder in eclipse. You will be prompted and choose "copy to new folders", which is the first option. And enjoy compiling and debugging in Eclipse.

要将您的项目导入在其他编辑器(如 Textpad 等)中编码的 Eclipse,只需打开 Eclipse 并创建一个新项目,展开您的项目,然后转到您的文件夹,将您的.java文件和其他包并将其拖到eclipse 中的源文件夹。系统将提示您并选择“复制到新文件夹”,这是第一个选项。并享受在 Eclipse 中编译和调试的乐趣。

回答by user7039739

  1. Copy and paste Example.java to package Eclipse(called custommath).
  2. Copy and paste input file to package Eclipse.
  3. You modified Example.java with package custommath,in first line instead of the input file.
  1. 将 Example.java 复制并粘贴到 Eclipse 包中(称为 custommath)。
  2. 将输入文件复制并粘贴到 Eclipse 包中。
  3. 您在第一行而不是输入文件中使用包 custommath 修改了 Example.java。