如何将 Eclipse 默认项目更改为 Java 项目

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

How to change an Eclipse default project into a Java project

javaeclipse

提问by Joe Dean

I checked out a project from SVN and did not specify the project type, so it checked out as a "default" project. What is the easiest way to quickly convert this into a "Java" project?

我从SVN签出一个项目,并没有指定项目类型,所以它作为“默认”项目签出。将其快速转换为“Java”项目的最简单方法是什么?

I'm using Eclipse version 3.3.2.

我使用的是 Eclipse 3.3.2 版。

采纳答案by Chris Marasti-Georg

Open the .project file and add java nature and builders.

打开 .project 文件并添加 java 自然和构建器。

<projectDescription>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

And in .classpath, reference the Java libs:

在 .classpath 中,引用 Java 库:

<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>

回答by Joe Dean

I deleted the project without removing content. I then created a new Java project from an existing resource. Pointing at my SVN checkout root folder. This worked for me. Although, Chris' way would have been much quicker. That's good to note for future. Thanks!

我删除了项目但没有删除内容。然后,我从现有资源创建了一个新的 Java 项目。指向我的 SVN 结帐根文件夹。这对我有用。虽然,克里斯的方式会快得多。这很好,以备将来注意。谢谢!

回答by Chris J

Joe's approach is actually the most effective means that I have found for doing this conversation. To elaborate a little bit more on it, you should right click on the project in the package explorer in eclipse and then select to delete it without removing directory or its contents. Next, you select to create a Java project (File -> New -> Java Project) and in the Contents part of the New Java Project dialog box, select 'Create project from existing source'.

乔的方法实际上是我找到的最有效的方法来进行这次谈话。为了更详细地说明它,您应该在 eclipse 中的包资源管理器中右键单击该项目,然后选择删除它而不删除目录或其内容。接下来,您选择创建一个 Java 项目(文件 -> 新建 -> Java 项目),并在“新建 Java 项目”对话框的内容部分中,选择“从现有源创建项目”。

The advantage this approach is that source folders will be properly identified. I found that mucking around with the .project file can lead to the entire directory being considered a source folder which is not what you want.

这种方法的优点是可以正确识别源文件夹。我发现处理 .project 文件会导致整个目录被视为不是您想要的源文件夹。

回答by Lorenzo

Manually changing XML and/or settings is very dangerous in eclipse unless you know exactly what you're doing. In the other case you might end up finding your complete project is screwed. Taking a backup is very recommended!

在 Eclipse 中手动更改 XML 和/或设置非常危险,除非您确切地知道自己在做什么。在另一种情况下,您最终可能会发现整个项目都被搞砸了。非常建议备份!

How to do it just using Eclipse?

仅使用 Eclipse 如何做到这一点?

  1. Select project.
  2. Open the project properties through Project -> Properties.
  3. Go to "Targetted Runtimes" and add the proper runtime. Click APPLY.
  4. Go to "Project Facets" and select the JAVA facet which has appeared due to step 4. Click APPLY
  5. Set your build path.
  6. If it's a Maven project, you might want to select the project, click Maven -> Update Project configuration...
  1. 选择项目。
  2. 通过 Project -> Properties 打开项目属性。
  3. 转到“目标运行时”并添加适当的运行时。单击应用。
  4. 转到“Project Facets”并选择由于第 4 步而出现的 JAVA facet。单击 APPLY
  5. 设置您的构建路径。
  6. 如果是 Maven 项目,您可能需要选择该项目,单击 Maven -> 更新项目配置...

That did it for me. And Eclipse is configured correctly. Hope it'll work for you too.

那是为我做的。并且 Eclipse 配置正确。希望它也对你有用。

回答by Victor Grazi

In recent versions of eclipse the fix is slightly different...

在最新版本的 eclipse 中,修复程序略有不同......

  1. Right click and select Project Properties
  2. Select Project Facets
  3. If necessary, click "Convert to faceted form"
  4. Select "Java" facet
  5. Click OK
  1. 右键单击并选择项目属性
  2. 选择项目构面
  3. 如有必要,请单击“转换为多面形式”
  4. 选择“Java”方面
  5. 单击确定

回答by drumherum

You can do it directly from eclipse using the Navigator view (Window -> Show View -> Navigator). In the Navigator view select the project and open it so that you can see the file .project. Right click -> Open. You will get a XML editor view. Edit the content of the node naturesand insert a new child naturewith org.eclipse.jdt.core.javanatureas content. Save.

您可以使用导航器视图(窗口 -> 显示视图 -> 导航器)直接从 Eclipse 中执行此操作。在 Navigator 视图中选择项目并打开它,以便您可以看到文件.project. 右键单击-> 打开。您将获得一个 XML 编辑器视图。编辑节点的内容natures并插入一个新的子natureorg.eclipse.jdt.core.javanature的内容。节省。

Now create a file .classpath, it will open in the XML editor. Add a node named classpath, add a child named classpathentrywith the attributes kindwith content conand another one named pathand content org.eclipse.jdt.launching.JRE_CONTAINER. Save-

现在创建一个文件.classpath,它将在 XML 编辑器中打开。添加一个名为 的节点classpath,添加一个以classpathentry属性命名的子节点kindwith contentcon和另一个命名为pathand content的子节点org.eclipse.jdt.launching.JRE_CONTAINER。节省-

Much easier: copythe files .projectand .classpathfrom an existing Java project and editthe node result nameto the name of this project. Maybe you have to refresh the project (F5).

更容易:从现有的 Java 项目复制文件.project,并将节点编辑为该项目的名称。也许您必须刷新项目(F5)。.classpathresult name

You'll get the same result as with the solution of Chris Marasti-Georg.

您将获得与 Chris Marasti-Georg 的解决方案相同的结果。

Edit

编辑

enter image description here

在此处输入图片说明

回答by Kumar

  1. Right click on project
  2. Configure -> 'Convert to Faceted Form'
  3. You will get a popup, Select 'Java' in 'Project Facet' column.
  4. Press Apply and Ok.
  1. 右键单击项目
  2. 配置 -> '转换为多面形式'
  3. 您将看到一个弹出窗口,在“Project Facet”列中选择“Java”。
  4. 按应用和确定。

回答by Brian de Alwis

Another possible way is to delete the project from Eclipse (but don't delete the project contents from disk!) and then use the New Java Projectwizard to create a project in-place. That wizard will detect the Java code and set up build paths automatically.

另一种可能的方法是从 Eclipse 中删除项目(但不要从磁盘中删除项目内容!),然后使用New Java Project向导就地创建项目。该向导将检测 Java 代码并自动设置构建路径。

回答by Premraj

Using project Project facetswe can configure characteristics and requirements for projects.

使用项目项目方面,我们可以配置项目的特征和要求。

To find Project facets on eclipse:

要在 Eclipse 上查找项目方面:

  • Step 1: Right click on the project and choose propertiesfrom the menu.
  • Step 2:Select project facetsoption. Click on Convert to faceted form...enter image description here

  • Step 3: We can find all available facets you can select and change their settings. enter image description here

  • 步骤 1:右键单击项目并properties从菜单中选择。
  • 第二步:选择project facets选项。点击Convert to faceted form...在此处输入图片说明

  • 第 3 步:我们可以找到所有可用的方面,您可以选择并更改其设置。 在此处输入图片说明

回答by Premraj

Depending on the Eclipse in question the required WTP packages may be found with different names. For example in Eclipse Luna I found it easiest to search with "Tools" and choose one that mentioned Tools for Java EE development. That added the project facet functionality. Searching with "WTP" wasn't of much help.

根据所讨论的 Eclipse,可能会发现所需的 WTP 包具有不同的名称。例如,在 Eclipse Luna 中,我发现使用“工具”进行搜索并选择一个提到 Java EE 开发工具的方法是最容易的。这增加了项目方面的功能。使用“WTP”进行搜索并没有多大帮助。