Java 为什么“找不到要导入的项目”?

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

Why "no projects found to import"?

javaeclipseimportproject

提问by Roman

I am trying to "import existing project into workspace". As the "root directory" I select the directory where all my .java (and .class) files are located. Eclipse writes me that "no projects are found to import". Why?

我正在尝试“将现有项目导入工作区”。作为“根目录”,我选择了所有 .java(和 .class)文件所在的目录。Eclipse 写信给我说“找不到要导入的项目”。为什么?

采纳答案by laura

Eclipse is looking for eclipse projects, meaning its is searching for eclipse-specific files in the root directory, namely .projectand .classpath. You either gave Eclipse the wrong directory (if you are importing a eclipse project) or you actually want to create a new project from existing source(new->java project->create project from existing source).

Eclipse是寻找Eclipse项目,这意味着它正在寻找Eclipse的特定文件的根目录,即.project.classpath。您要么为 Eclipse 提供了错误的目录(如果您要导入 Eclipse 项目),要么您实际上想从现有源(new-> java project-> create project from existing source)创建一个新项目。

I think you probably want the second one, because Eclipse projects usually have separate source & build directories. If your sources and .class files are in the same directory, you probably didn't have a eclipse project.

我想你可能想要第二个,因为 Eclipse 项目通常有单独的源和构建目录。如果您的源代码和 .class 文件位于同一目录中,则您可能没有 Eclipse 项目。

回答by Saher Ahwal

This answer is same as Laura's answer , however, in new eclipse versions you will not be able to see a "create project from existing source" option.

这个答案与劳拉的答案相同,但是,在新的 Eclipse 版本中,您将看不到“从现有源创建项目”选项。

Hence you can do this instead:

因此,您可以这样做:

  • Goto File> New> Project

  • Select the type of project, click Next

  • Uncheck Use default location

  • Click on Browseto navigate to your source folder, or type in the path to your source

  • Click Finish

  • 转到文件>新建>项目

  • 选择项目类型,点击下一步

  • 取消选中使用默认位置

  • 单击“浏览”以导航到源文件夹,或输入源路径

  • 单击完成

Taken from this discussion forumin eclipse.org

摘自eclipse.org 中的 这个讨论论坛

回答by PaulF

One solution to this is to use Maven. From the project root folder do mvn eclipse:clean followed by mvn eclipse:eclipse. This will generate the .project and .classpath files required by eclipse.

对此的一种解决方案是使用 Maven。从项目根文件夹执行 mvn eclipse:clean 后跟 mvn eclipse:eclipse。这将生成 eclipse 所需的 .project 和 .classpath 文件。

回答by Monica M

In new updated eclipse the option "create project from existing source" is found here, File>New>Project>Android>AndroidProject from Existing Code. Then browse to root directory.

在新更新的 eclipse 中,可以create project from existing source在此处找到选项“ ”, File>New>Project>Android>Android来自现有代码的项目。然后浏览到根目录。

enter image description here

在此处输入图片说明

回答by Piotr Czy?

I had the same issue when I've modified .project xml-file. When I reverted files to original version the project was created, then I was able to import project. Maybe it helps someone who has the same kind of problem ;)

当我修改 .project xml 文件时,我遇到了同样的问题。当我将文件恢复到创建项目的原始版本时,我就可以导入项目了。也许它可以帮助有同样问题的人;)

回答by ChrisThompson

if you are building a maven project through a command console, make sure the following is at the end of the command:

如果您是通过命令控制台构建 Maven 项目,请确保以下内容位于命令末尾:

eclipse:eclipse -Dwtpversion=2.0

回答by Vsw10

In order to resolve this problem for android projects. follow the below mentioned steps new->android project->create project from existing source and in this you can give your code location. Now, it will import all the specified project code and will work fine

为了解决android项目的这个问题。按照下面提到的步骤 new->android project->create project from existing source ,在此您可以提供您的代码位置。现在,它将导入所有指定的项目代码并且可以正常工作

回答by Patrick

If you don't have I just have .projectand .classpathfiles in the directory, the only way that works (for me at least) with the latest version of Eclipse is:

如果目录中没有 I just have.project.classpathfiles,则适用于最新版本 Eclipse 的唯一方法(至少对我而言)是:

  1. Create a new Android project
    • File-> New-> Project...-> Android-> Android Application Project-> Next >
    • Fill in the values on this page and the following according to your application's needs
  2. Get your existing code into the project you just created
    • Right click the srcfile in the Package Explorer
    • General-> File System-> Next >
    • Browseto your project, select the necessary files, hit Finish
  1. 创建一个新的安卓项目
    • File-> New-> Project...-> Android-> Android Application Project->Next >
    • 根据您的应用程序需要填写此页面上的值和以下内容
  2. 将现有代码放入刚刚创建的项目中
    • 右键单击src包资源管理器中的文件
    • General-> File System->Next >
    • Browse到您的项目,选择必要的文件,点击 Finish

After this, you should have a project with all your existing code as well as new .projectand .classpathfiles.

在这之后,你应该有你所有的现有代码的项目,以及新的.project.classpath文件。

回答by Hadi hashemi

After a long time finally i found that! Here my Way: File -> New Project -> Android Project From Existing Code -> Browse to your project root directory finish!

找了好久终于找到了!这是我的方式:文件 -> 新建项目 -> 来自现有代码的 Android 项目 -> 浏览到您的项目根目录完成!

回答by Mai

I have a perfect solution for this problem. After doing following simple steps you will be able to Import your source codes in Eclipse!

对于这个问题,我有一个完美的解决方案。完成以下简单步骤后,您将能够在 Eclipse 中导入源代码!


First of all, the reasonwhy you can not Import your project into Eclipse workstation is that you do not have .projectand .classpathfile.


首先,该理由为什么你不能导入项目到Eclipse工作站是你没有的.project的.classpath文件。

Now we know why this happens, so all we need to do is to create .projectand .classpathfile inside the project file. Here is how you do it:

现在我们知道为什么会发生这种情况,所以我们需要做的就是在项目文件中创建.project.classpath文件。这是你如何做到的:



First create .classpathfile:

首先创建.classpath文件:

  1. create a new txt file and name it as .classpath
  2. copy paste following codes and save it:

    <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="bin"/> </classpath>

  1. 创建一个新的 txt 文件并将其命名为 .classpath
  2. 复制粘贴以下代码并保存:

    <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="bin"/> </classpath>



Then create .projectfile:



然后创建 .project文件:

  1. create a new txt file and name it as .project
  2. copy paste following codes:

    <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>HereIsTheProjectName</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription>

  3. you have to change the name field to your project name. you can do this in line 3 by changing HereIsTheProjectNameto your own project name. then save it.

  1. 创建一个新的 txt 文件并将其命名为 .project
  2. 复制粘贴以下代码:

    <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>HereIsTheProjectName</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription>

  3. 您必须将名称字段更改为您的项目名称。您可以在第 3 行中通过将HereIsTheProjectName更改为您自己的项目名称来完成此操作。然后保存它。


That is all, Enjoy!!


就是这样,享受!!