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

时间:2023-02-05 18:01:27

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版本。

10 个解决方案

#1


109  

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 libs:

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

#2


112  

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

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

这是为了我。Eclipse配置正确。希望这对你也有用。

#3


45  

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

在eclipse的最新版本中,修复方法略有不同……

  1. Right click and select Project Properties
  2. 右键单击并选择项目属性
  3. Select Project Facets
  4. 选择项目方面
  5. If necessary, click "Convert to faceted form"
  6. 如果需要,点击“转换为面形”
  7. Select "Java" facet
  8. 选择“Java”方面
  9. Click OK
  10. 单击OK

#4


22  

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签出根文件夹。这为我工作。虽然,克里斯的方式会快得多。这对未来很有意义。谢谢!

#5


11  

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的package explorer中右键单击项目,然后选择删除它,而不删除目录或其内容。接下来,您选择创建一个Java项目(File -> New -> 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文件的胡乱操作会导致整个目录被认为是一个源文件夹,这不是您想要的。

#6


9  

Using project Project facets we can configure characteristics and requirements for projects.

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

To find Project facets on eclipse:

要在eclipse上找到项目方面:

  • Step 1: Right click on the project and choose properties from the menu.
  • 步骤1:右键单击项目并从菜单中选择属性。
  • Step 2:Select project facets option. Click on Convert to faceted form... 如何将Eclipse默认项目更改为Java项目

    步骤2:选择项目facet选项。点击转换为面形…

  • Step 3: We can find all available facets you can select and change their settings. 如何将Eclipse默认项目更改为Java项目

    步骤3:我们可以找到所有可用的方面,您可以选择并更改它们的设置。

#7


5  

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 natures and insert a new child nature with org.eclipse.jdt.core.javanature as content. Save.

您可以使用Navigator视图(Window -> Show view -> Navigator)直接从eclipse完成它。在Navigator视图中选择项目并打开它,以便您可以看到file .project。点击右键- >打开。您将得到一个XML编辑器视图。编辑节点属性的内容,并使用org. eclipsee .jdt.core插入一个新的子属性。javanature内容。保存。

Now create a file .classpath, it will open in the XML editor. Add a node named classpath, add a child named classpathentry with the attributes kind with content con and another one named path and content org.eclipse.jdt.launching.JRE_CONTAINER. Save-

现在创建一个.classpath文件,它将在XML编辑器中打开。添加一个名为classpath的节点,添加一个名为classpathentry的子节点,该子节点的属性类型为content con,另一个为path和content org.eclipsee . jdt.launch.jre_container。保存,

Much easier: copy the files .project and .classpath from an existing Java project and edit the node result name to the name of this project. Maybe you have to refresh the project (F5).

更简单:从现有的Java项目中复制文件.project和.classpath,并将节点结果名编辑为这个项目的名称。也许你需要刷新项目(F5)。

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

你会得到和Chris Marasti-Georg一样的结果。

Edit

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

#8


3  

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 Project wizard to create a project in-place. That wizard will detect the Java code and set up build paths automatically.

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

#9


1  

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

#10


1  

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”搜索并没有多大帮助。

#1


109  

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 libs:

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

#2


112  

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

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

这是为了我。Eclipse配置正确。希望这对你也有用。

#3


45  

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

在eclipse的最新版本中,修复方法略有不同……

  1. Right click and select Project Properties
  2. 右键单击并选择项目属性
  3. Select Project Facets
  4. 选择项目方面
  5. If necessary, click "Convert to faceted form"
  6. 如果需要,点击“转换为面形”
  7. Select "Java" facet
  8. 选择“Java”方面
  9. Click OK
  10. 单击OK

#4


22  

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签出根文件夹。这为我工作。虽然,克里斯的方式会快得多。这对未来很有意义。谢谢!

#5


11  

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的package explorer中右键单击项目,然后选择删除它,而不删除目录或其内容。接下来,您选择创建一个Java项目(File -> New -> 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文件的胡乱操作会导致整个目录被认为是一个源文件夹,这不是您想要的。

#6


9  

Using project Project facets we can configure characteristics and requirements for projects.

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

To find Project facets on eclipse:

要在eclipse上找到项目方面:

  • Step 1: Right click on the project and choose properties from the menu.
  • 步骤1:右键单击项目并从菜单中选择属性。
  • Step 2:Select project facets option. Click on Convert to faceted form... 如何将Eclipse默认项目更改为Java项目

    步骤2:选择项目facet选项。点击转换为面形…

  • Step 3: We can find all available facets you can select and change their settings. 如何将Eclipse默认项目更改为Java项目

    步骤3:我们可以找到所有可用的方面,您可以选择并更改它们的设置。

#7


5  

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 natures and insert a new child nature with org.eclipse.jdt.core.javanature as content. Save.

您可以使用Navigator视图(Window -> Show view -> Navigator)直接从eclipse完成它。在Navigator视图中选择项目并打开它,以便您可以看到file .project。点击右键- >打开。您将得到一个XML编辑器视图。编辑节点属性的内容,并使用org. eclipsee .jdt.core插入一个新的子属性。javanature内容。保存。

Now create a file .classpath, it will open in the XML editor. Add a node named classpath, add a child named classpathentry with the attributes kind with content con and another one named path and content org.eclipse.jdt.launching.JRE_CONTAINER. Save-

现在创建一个.classpath文件,它将在XML编辑器中打开。添加一个名为classpath的节点,添加一个名为classpathentry的子节点,该子节点的属性类型为content con,另一个为path和content org.eclipsee . jdt.launch.jre_container。保存,

Much easier: copy the files .project and .classpath from an existing Java project and edit the node result name to the name of this project. Maybe you have to refresh the project (F5).

更简单:从现有的Java项目中复制文件.project和.classpath,并将节点结果名编辑为这个项目的名称。也许你需要刷新项目(F5)。

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

你会得到和Chris Marasti-Georg一样的结果。

Edit

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

#8


3  

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 Project wizard to create a project in-place. That wizard will detect the Java code and set up build paths automatically.

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

#9


1  

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

#10


1  

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”搜索并没有多大帮助。