I have created several .java files. All of them are located in one directory. I used a text editor to write these files. Now I want to switch to Eclipse. How can I do it? I have tried many ways. None of them works.
我创建了几个.java文件。它们都位于一个目录中。我使用文本编辑器来编写这些文件。现在我想切换到Eclipse。我该怎么做呢?我尝试过很多方法。没有人工作。
ADDED:
补充道:
I think the common way is to have source in the eclipse folder called "workspace". So, how do I get my files in these directory. Should I use eclipse to create a new project from existing source and Eclipse will put all file to the workspace? Or I should manually copy all my files to the workspace? Where should I put my class files than? Should I create a subdirectory? With which name?
我认为常见的方法是在eclipse文件夹中有一个名为“workspace”的源文件。那么,如何在这些目录中获取文件呢?我是否应该使用eclipse从现有的源创建一个新项目,eclipse将把所有文件放到工作区中?或者我应该手动将所有文件复制到工作区?我应该把我的类文件放在哪里?我应该创建一个子目录吗?的名字吗?
ADDED 2:
补充2:
When I try to create a project with name "game", the eclipse writes me that a project with such name already exist. But how can I open this project?
当我尝试创建一个名为“game”的项目时,eclipse会告诉我已经存在这样一个项目。但是我如何打开这个项目呢?
ADDED 3:
添加3:
In my "workspace" I have created a subdirectory called "game". I copied all my .java file into this subdirectory. Then with Eclipse I created a new project with the name game. As a result, Eclipse created .classpath
and .project
files in the directory "game". It also created bin
and src
subdirectories. And now I think it is not the correct way to go. The source files are supposed to be in the "src" directory. Right? And at the moment all my .java files are in the "workspace\game".
在我的“工作区”中,我创建了一个名为“game”的子目录。我将所有的.java文件复制到这个子目录中。然后我用Eclipse创建了一个名为game的新项目。因此,Eclipse在目录“游戏”中创建了.classpath和.project文件。它还创建了bin和src子目录。现在我认为这不是正确的方法。源文件应该在“src”目录中。对吧?目前,我所有的.java文件都在“工作空间\游戏”中。
ADDED 4:
添加4:
I did it other way around. With Eclipse I have created a new project with the name "game". As the result, Eclipse created a folder called "game" into folder "workspace". In "game" the folder I found "src" folder. I copied all my .java files into this folder. But now in the "Package Explorer" I cannot open "src" folder. So, how can I access my source files from Eclipse? Why Eclipse does not want to open the "src" folder?
我用了另一种方法。使用Eclipse,我创建了一个名为“game”的新项目。因此,Eclipse在“工作区”文件夹中创建了一个名为“game”的文件夹。在“游戏”文件夹中,我找到了“src”文件夹。我将所有的.java文件复制到这个文件夹中。但是现在在“Package Explorer”中,我不能打开“src”文件夹。那么,如何从Eclipse访问源文件呢?为什么Eclipse不想打开“src”文件夹?
11 个解决方案
#1
232
Easiest Method:
最简单的方法:
- Put all source files into one directory named after your project. i.e. "ProjectName" You can keep this directory in your workspace or it can be somewhere else.
- 将所有源文件放在一个以项目命名的目录中。即。“ProjectName”可以将这个目录保存在工作区中,也可以放在其他地方。
- Start a new project in eclipse and name it using that same project name.
- 在eclipse中启动一个新项目,并使用相同的项目名称对其命名。
- Uncheck the "use default location" box and find the directory where your project is unless your project is already in the workspace - then you must not uncheck the "use default location" box
- 取消“使用默认位置”框,并找到项目所在的目录,除非您的项目已经在工作区中—那么您不能取消“使用默认位置”框
- Click 'next'.
- 单击“next”。
Eclipse should be smart enough to figure out what's going on. After clicking next, it will show you all of the files it found in that directory. It will just automatically add those files to your project. Voilà!
Eclipse应该足够聪明,能够弄清楚到底发生了什么。单击next之后,它将显示在该目录中找到的所有文件。它会自动将这些文件添加到您的项目中。瞧!
#2
6
- Right-click in the package explorer and select New - Java Project
- 右键单击package explorer并选择New - Java项目
- Create the new project Game
- 创建新的项目游戏
- Open the new project in the package explorer - you should see only the source folder called src (there's nothing inside yet)
- 在package explorer中打开新项目——应该只看到名为src的源文件夹(里面还没有文件)
- Open a file Explorer (e.g. Windows Explorer) and drag your sources
- 打开文件资源管理器(例如Windows资源管理器)并拖动源代码
- Drag them to Eclipse and drop them inside the new src folder - if asked select "Copy files"
- 将它们拖到Eclipse并将它们放到新的src文件夹中—如果需要,请选择“复制文件”
- Eclipse should put the files into the default package, if that's not correct you can edit the offending files (marked with a red cross) by opening them in Eclipse, selecting the package declaration (usually line 1), pressing Ctrl + 1 and selecting the appropriate option (e.g. "Move xy to package com.game"
- Eclipse应该将这些文件放入默认的包中,如果不正确,可以通过在Eclipse中打开这些文件(通常是第1行)、按Ctrl + 1并选择适当的选项(例如,使用红色十字标记)来编辑这些文件。"移动xy到package com。game"
#3
3
This answer is going to be for the question
这个答案就是问题的答案
How to create a new eclipse project and add a folder or a new package into the project, or how to build a new project for existing java files.
如何创建一个新的eclipse项目并向项目中添加一个文件夹或一个新包,或者如何为现有的java文件构建一个新项目。
- Create a new project from the menu File->New-> Java Project
- 从菜单文件->新建-> Java项目创建一个新项目
- If you are going to add a new pakcage, then create the same package name here by File->New-> Package
- 如果要添加一个新的pakcage,那么在这里按File-> new ->包创建相同的包名
- Click the name of the package in project navigator, and right click, and import... Import->General->File system (choose your file or package)
- 单击project navigator中的包的名称,然后右键单击并导入…导入->通用->文件系统(选择您的文件或包)
this worked for me I hope it helps others. Thank you.
我希望这对其他人有帮助。谢谢你!
#4
1
There are two things
有两件事
1- If its already a Eclipse Project, then simply go to File->Import->General->Existing Project into Workplace
1-如果它已经是一个Eclipse项目,那么只需进入File->Import->General->现有项目到Workplace
2- Otherwise define project type e.g. Java, Web etc Create a new project of type you define into your workplace. Copy Paste source , lib and other necessary files. refresh, compile and run project in eclipse.
2-否则定义项目类型,例如Java, Web等等,创建一个你在工作场所定义的类型的新项目。复制粘贴源、库和其他必要的文件。在eclipse中刷新、编译和运行项目。
#5
1
The easiest method is really good but you don't get a standard Java project, i.e., the .java and .class files separated in different folders.
最简单的方法确实很好,但是您不会得到一个标准的Java项目,例如。,将.java和.class文件分隔在不同的文件夹中。
To get this very easily:
要做到这点很容易:
- Create a folder called "ProjectName" on the workspace of Eclipse.
- 在Eclipse的工作区上创建一个名为“ProjectName”的文件夹。
- Copy or move your folder with the .java files to the "ProjectName" folder.
- 将.java文件中的文件夹复制或移动到“ProjectName”文件夹。
- Create a new Java Project called "ProjectName" (with the Use default location marked).
- 创建一个名为“ProjectName”的新Java项目(使用默认位置标记)。
- Press
<Enter>
and that's it. -
按
,就这样。
#6
0
In the package explorer and the navigation screen you should now see the project you created. Note that eclipse will not copy your files, it will just allow you to use the existing source and edit it from eclipse.
在package explorer和导航屏幕中,您现在应该看到您创建的项目。注意,eclipse不会复制您的文件,它只允许您使用现有的源代码并从eclipse编辑它。
#7
0
There are several ways to add files to an existing Java project in Eclipse. So lets assume you have already created the Java project in Eclipse (e.g. using File
-> New
-> Project...
- and select Java project
).
有几种方法可以将文件添加到Eclipse中现有的Java项目中。因此,假设您已经在Eclipse中创建了Java项目(例如,使用File -> New ->项目……)-并选择Java项目)。
To get Java files into the new project you can do any of the following. Note that there are other ways as well. The sequence is my preference.
要将Java文件放到新项目中,可以执行以下任何一种操作。注意还有其他的方法。顺序是我的偏好。
- Drag the files into the
Navigator
view directly from the native file manager. You must create any needed Java packages first. This method is best for a few files in an existing Java package. - 将文件直接从本机文件管理器拖放到Navigator视图中。您必须首先创建任何需要的Java包。此方法最适合现有Java包中的几个文件。
- Use
File
->Import...
- selectFile System
. Here you can then select exactly which files to import into the new project and in which Java package to put them. This is extremely handy if you want to import many files or there are multiple Java packages. - 使用文件- >导入……——选择文件系统。在这里,您可以选择将哪些文件导入到新项目中,以及将它们放入哪个Java包中。如果您想要导入许多文件或有多个Java包,这非常方便。
- Copy the fires directly to the folder/directory in the workspace and then use
File
->Refresh
to refresh the Eclipse view of the native system. Remember to select the new project before the refresh. - 将fire直接复制到工作区中的文件夹/目录,然后使用File ->刷新来刷新本机系统的Eclipse视图。记住在刷新之前选择新项目。
The last one is what you did - minus the refresh...
最后一个是你做的-减去刷新…
#8
0
While creating a project from a full folder may or may not work within the workspace, there's a condition outside of the workspace that prevents starting a new project with a full folder.
虽然从完整文件夹创建项目可能在工作区中工作,也可能不工作,但是工作区之外有一个条件阻止使用完整文件夹启动新项目。
This is relevant if you use numerous folder locations for sources, for example an htdocs or www folder for web projects, and a different location for desktop Java applications.
如果您对源文件使用大量的文件夹位置,例如用于web项目的htdocs或www文件夹,以及用于桌面Java应用程序的不同位置,那么这一点是相关的。
The condition mentioned occurs when Eclipse is told to create a new project, and given a full folder outside the workspace. Eclipse will say the folder isn't empty, and prevent creating a new project within the given folder. I haven't found a way around this, and any solution requires extra steps.
当Eclipse被告知要创建一个新项目,并在工作区之外提供一个完整的文件夹时,就会出现上述情况。Eclipse会说文件夹不是空的,并防止在给定的文件夹中创建新项目。我还没有找到解决这个问题的方法,任何解决方案都需要额外的步骤。
My favorite solution is as follows
我最喜欢的解决方案如下
- Rename the full folder with an appended "Original" or "Backup.
- 用附加的“原始”或“备份”重命名完整文件夹。
- Create the Eclipse project with the name of the full folder before the folder was renamed.
- 在重新命名文件夹之前,使用完整文件夹的名称创建Eclipse项目。
- Copy all the relabeled full folders contents into the new project folder.
- 将所有的文件夹内容复制到新的项目文件夹中。
Eclipse should make a new project, and update that project with the new folder contents as it scans for changes. The existing sources are now part of the new project.
Eclipse应该创建一个新项目,并在扫描更改时使用新文件夹内容更新该项目。现有的资源现在是新项目的一部分。
Although you had to perform three extra steps, you now have a backup with the original sources available, and are also able to use a copy of them in an existing project. If storage space is a concern, simply move/cut the source rather than fully copy the original folder contents.
虽然您必须执行三个额外的步骤,但是您现在有了一个具有可用原始源的备份,并且还能够在现有项目中使用它们的副本。如果需要考虑存储空间,只需移动/剪切源文件,而不是完全复制原始文件夹内容。
#9
0
If you creating a new project based on an existing Maven structure :
如果您基于现有的Maven结构创建一个新项目:
Create the project using a general project wizard and give the project the same name as just created.
使用通用的项目向导创建项目,并为项目提供与刚才创建的名称相同的名称。
If you try to create the project as a Maven project via m2e will receive an error that project/pom already exists.
如果您试图通过m2e将项目创建为Maven项目,则会收到项目/pom已经存在的错误。
#10
0
- Create a new project..
- 创建一个新项目。
- Right Click on your project..
- 右键点击你的项目。
- Select Build path --> Configure Build Path
- 选择构建路径——>配置构建路径
- Under source tab choose link source, your .java files containing folder..
- 在source选项卡下选择link source,你的.java文件包含文件夹。
I am suggesting this since none of the methods that you tried have worked ---FYI
我是这么建议的,因为你尝试过的所有方法都没有起作用
#11
-1
Follow this instructions from standard eclipse docs.
按照来自标准eclipse文档的说明。
- From the main menu bar, select command link File > Import.... The Import wizard opens.
- 从主菜单栏,选择命令链接文件>导入....打开导入向导。
- Select General > Existing Project into Workspace and click Next.
- 在工作区中选择常规>现有项目并单击Next。
- Choose either Select root directory or Select archive file and click the associated Browse to locate the directory or file containing the projects.
- 选择“选择根目录”或“选择归档文件”,然后单击“关联浏览”以找到包含项目的目录或文件。
- Under Projects select the project or projects which you would like to import.
- 在“项目”下,选择要导入的项目或项目。
- Click Finish to start the import.
- 单击Finish开始导入。
#1
232
Easiest Method:
最简单的方法:
- Put all source files into one directory named after your project. i.e. "ProjectName" You can keep this directory in your workspace or it can be somewhere else.
- 将所有源文件放在一个以项目命名的目录中。即。“ProjectName”可以将这个目录保存在工作区中,也可以放在其他地方。
- Start a new project in eclipse and name it using that same project name.
- 在eclipse中启动一个新项目,并使用相同的项目名称对其命名。
- Uncheck the "use default location" box and find the directory where your project is unless your project is already in the workspace - then you must not uncheck the "use default location" box
- 取消“使用默认位置”框,并找到项目所在的目录,除非您的项目已经在工作区中—那么您不能取消“使用默认位置”框
- Click 'next'.
- 单击“next”。
Eclipse should be smart enough to figure out what's going on. After clicking next, it will show you all of the files it found in that directory. It will just automatically add those files to your project. Voilà!
Eclipse应该足够聪明,能够弄清楚到底发生了什么。单击next之后,它将显示在该目录中找到的所有文件。它会自动将这些文件添加到您的项目中。瞧!
#2
6
- Right-click in the package explorer and select New - Java Project
- 右键单击package explorer并选择New - Java项目
- Create the new project Game
- 创建新的项目游戏
- Open the new project in the package explorer - you should see only the source folder called src (there's nothing inside yet)
- 在package explorer中打开新项目——应该只看到名为src的源文件夹(里面还没有文件)
- Open a file Explorer (e.g. Windows Explorer) and drag your sources
- 打开文件资源管理器(例如Windows资源管理器)并拖动源代码
- Drag them to Eclipse and drop them inside the new src folder - if asked select "Copy files"
- 将它们拖到Eclipse并将它们放到新的src文件夹中—如果需要,请选择“复制文件”
- Eclipse should put the files into the default package, if that's not correct you can edit the offending files (marked with a red cross) by opening them in Eclipse, selecting the package declaration (usually line 1), pressing Ctrl + 1 and selecting the appropriate option (e.g. "Move xy to package com.game"
- Eclipse应该将这些文件放入默认的包中,如果不正确,可以通过在Eclipse中打开这些文件(通常是第1行)、按Ctrl + 1并选择适当的选项(例如,使用红色十字标记)来编辑这些文件。"移动xy到package com。game"
#3
3
This answer is going to be for the question
这个答案就是问题的答案
How to create a new eclipse project and add a folder or a new package into the project, or how to build a new project for existing java files.
如何创建一个新的eclipse项目并向项目中添加一个文件夹或一个新包,或者如何为现有的java文件构建一个新项目。
- Create a new project from the menu File->New-> Java Project
- 从菜单文件->新建-> Java项目创建一个新项目
- If you are going to add a new pakcage, then create the same package name here by File->New-> Package
- 如果要添加一个新的pakcage,那么在这里按File-> new ->包创建相同的包名
- Click the name of the package in project navigator, and right click, and import... Import->General->File system (choose your file or package)
- 单击project navigator中的包的名称,然后右键单击并导入…导入->通用->文件系统(选择您的文件或包)
this worked for me I hope it helps others. Thank you.
我希望这对其他人有帮助。谢谢你!
#4
1
There are two things
有两件事
1- If its already a Eclipse Project, then simply go to File->Import->General->Existing Project into Workplace
1-如果它已经是一个Eclipse项目,那么只需进入File->Import->General->现有项目到Workplace
2- Otherwise define project type e.g. Java, Web etc Create a new project of type you define into your workplace. Copy Paste source , lib and other necessary files. refresh, compile and run project in eclipse.
2-否则定义项目类型,例如Java, Web等等,创建一个你在工作场所定义的类型的新项目。复制粘贴源、库和其他必要的文件。在eclipse中刷新、编译和运行项目。
#5
1
The easiest method is really good but you don't get a standard Java project, i.e., the .java and .class files separated in different folders.
最简单的方法确实很好,但是您不会得到一个标准的Java项目,例如。,将.java和.class文件分隔在不同的文件夹中。
To get this very easily:
要做到这点很容易:
- Create a folder called "ProjectName" on the workspace of Eclipse.
- 在Eclipse的工作区上创建一个名为“ProjectName”的文件夹。
- Copy or move your folder with the .java files to the "ProjectName" folder.
- 将.java文件中的文件夹复制或移动到“ProjectName”文件夹。
- Create a new Java Project called "ProjectName" (with the Use default location marked).
- 创建一个名为“ProjectName”的新Java项目(使用默认位置标记)。
- Press
<Enter>
and that's it. -
按
,就这样。
#6
0
In the package explorer and the navigation screen you should now see the project you created. Note that eclipse will not copy your files, it will just allow you to use the existing source and edit it from eclipse.
在package explorer和导航屏幕中,您现在应该看到您创建的项目。注意,eclipse不会复制您的文件,它只允许您使用现有的源代码并从eclipse编辑它。
#7
0
There are several ways to add files to an existing Java project in Eclipse. So lets assume you have already created the Java project in Eclipse (e.g. using File
-> New
-> Project...
- and select Java project
).
有几种方法可以将文件添加到Eclipse中现有的Java项目中。因此,假设您已经在Eclipse中创建了Java项目(例如,使用File -> New ->项目……)-并选择Java项目)。
To get Java files into the new project you can do any of the following. Note that there are other ways as well. The sequence is my preference.
要将Java文件放到新项目中,可以执行以下任何一种操作。注意还有其他的方法。顺序是我的偏好。
- Drag the files into the
Navigator
view directly from the native file manager. You must create any needed Java packages first. This method is best for a few files in an existing Java package. - 将文件直接从本机文件管理器拖放到Navigator视图中。您必须首先创建任何需要的Java包。此方法最适合现有Java包中的几个文件。
- Use
File
->Import...
- selectFile System
. Here you can then select exactly which files to import into the new project and in which Java package to put them. This is extremely handy if you want to import many files or there are multiple Java packages. - 使用文件- >导入……——选择文件系统。在这里,您可以选择将哪些文件导入到新项目中,以及将它们放入哪个Java包中。如果您想要导入许多文件或有多个Java包,这非常方便。
- Copy the fires directly to the folder/directory in the workspace and then use
File
->Refresh
to refresh the Eclipse view of the native system. Remember to select the new project before the refresh. - 将fire直接复制到工作区中的文件夹/目录,然后使用File ->刷新来刷新本机系统的Eclipse视图。记住在刷新之前选择新项目。
The last one is what you did - minus the refresh...
最后一个是你做的-减去刷新…
#8
0
While creating a project from a full folder may or may not work within the workspace, there's a condition outside of the workspace that prevents starting a new project with a full folder.
虽然从完整文件夹创建项目可能在工作区中工作,也可能不工作,但是工作区之外有一个条件阻止使用完整文件夹启动新项目。
This is relevant if you use numerous folder locations for sources, for example an htdocs or www folder for web projects, and a different location for desktop Java applications.
如果您对源文件使用大量的文件夹位置,例如用于web项目的htdocs或www文件夹,以及用于桌面Java应用程序的不同位置,那么这一点是相关的。
The condition mentioned occurs when Eclipse is told to create a new project, and given a full folder outside the workspace. Eclipse will say the folder isn't empty, and prevent creating a new project within the given folder. I haven't found a way around this, and any solution requires extra steps.
当Eclipse被告知要创建一个新项目,并在工作区之外提供一个完整的文件夹时,就会出现上述情况。Eclipse会说文件夹不是空的,并防止在给定的文件夹中创建新项目。我还没有找到解决这个问题的方法,任何解决方案都需要额外的步骤。
My favorite solution is as follows
我最喜欢的解决方案如下
- Rename the full folder with an appended "Original" or "Backup.
- 用附加的“原始”或“备份”重命名完整文件夹。
- Create the Eclipse project with the name of the full folder before the folder was renamed.
- 在重新命名文件夹之前,使用完整文件夹的名称创建Eclipse项目。
- Copy all the relabeled full folders contents into the new project folder.
- 将所有的文件夹内容复制到新的项目文件夹中。
Eclipse should make a new project, and update that project with the new folder contents as it scans for changes. The existing sources are now part of the new project.
Eclipse应该创建一个新项目,并在扫描更改时使用新文件夹内容更新该项目。现有的资源现在是新项目的一部分。
Although you had to perform three extra steps, you now have a backup with the original sources available, and are also able to use a copy of them in an existing project. If storage space is a concern, simply move/cut the source rather than fully copy the original folder contents.
虽然您必须执行三个额外的步骤,但是您现在有了一个具有可用原始源的备份,并且还能够在现有项目中使用它们的副本。如果需要考虑存储空间,只需移动/剪切源文件,而不是完全复制原始文件夹内容。
#9
0
If you creating a new project based on an existing Maven structure :
如果您基于现有的Maven结构创建一个新项目:
Create the project using a general project wizard and give the project the same name as just created.
使用通用的项目向导创建项目,并为项目提供与刚才创建的名称相同的名称。
If you try to create the project as a Maven project via m2e will receive an error that project/pom already exists.
如果您试图通过m2e将项目创建为Maven项目,则会收到项目/pom已经存在的错误。
#10
0
- Create a new project..
- 创建一个新项目。
- Right Click on your project..
- 右键点击你的项目。
- Select Build path --> Configure Build Path
- 选择构建路径——>配置构建路径
- Under source tab choose link source, your .java files containing folder..
- 在source选项卡下选择link source,你的.java文件包含文件夹。
I am suggesting this since none of the methods that you tried have worked ---FYI
我是这么建议的,因为你尝试过的所有方法都没有起作用
#11
-1
Follow this instructions from standard eclipse docs.
按照来自标准eclipse文档的说明。
- From the main menu bar, select command link File > Import.... The Import wizard opens.
- 从主菜单栏,选择命令链接文件>导入....打开导入向导。
- Select General > Existing Project into Workspace and click Next.
- 在工作区中选择常规>现有项目并单击Next。
- Choose either Select root directory or Select archive file and click the associated Browse to locate the directory or file containing the projects.
- 选择“选择根目录”或“选择归档文件”,然后单击“关联浏览”以找到包含项目的目录或文件。
- Under Projects select the project or projects which you would like to import.
- 在“项目”下,选择要导入的项目或项目。
- Click Finish to start the import.
- 单击Finish开始导入。