如何将 GIT 非 Eclipse Java 项目导入 Eclipse? [英] How to import a GIT non-Eclipse Java project into Eclipse?

查看:30
本文介绍了如何将 GIT 非 Eclipse Java 项目导入 Eclipse?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将 Java 项目导入到我的工作区时遇到了一些问题.我正在关注本教程 - 但是我无法使用最终的导入现有项目 步骤,因为我使用的 GIT 存储库不包含 Eclipse 特定的 .project.classpath 文件.

I have some problems importing a Java project into my workspace. I am following this tutorial - however I can not use the final Import existing projects step because the GIT repository I use does not include the Eclipse specific .project and .classpath files.

因此项目不被识别为项目,因此无法导入.因此,我尝试使用选项使用新建项目向导 并在下一个对话框中选择Java 项目".问题是这会创建一个没有任何内容的新 Java 项目!该项目也未连接到 GIT 存储库.

Therefore the project is not recognizes as project and hence can not be imported. Therefore I tried my luck using the option Use the New Projects wizard and select "Java Project" in the next dialog. The problem is that this creates a new Java project without any content! The project is also not connected to the GIT repository.

这是 eGIT 的一个已知错误:错误 324145 - 项目导入不适用于 abitary项目类型 - 如果你想要这个问题固定投票......

This is a known bug of eGIT: Bug 324145 - Project import doesn't work for abitary project types - if you want this problem fixed vote for it...

如果我使用作为一般项目导入 Eclipse 总是想使用外部存储库目录作为项目目录,这不是我想要的,而且创建的项目不支持 Java.

If I use Import as general Project Eclipse always wants to use the external repository directory as project directory which is not what I want and additionally the created Project is not Java-enabled.

所以我想问为什么使用eGIT将Java项目导入Eclipse这么复杂?

推荐答案

可以先克隆存储库,然后在此基础上创建一个 General 项目.然后您可以将其转换为 Java 项目.方法如下:

It is possible by first cloning the repository and then creating a General project based on that. Then you can convert it to Java project. Here is how:

  • 首先进入File>Import...>Projects from GIT.
  • Select a Git Repository 视图中,您首先按下 Clone.并遵照指示.这将为您的计算机创建存储库的本地签出".您可以将该文件夹设置为您的工作区,这样它看起来就像您的任何其他 Eclipse 项目.
  • 克隆存储库后,您将返回Import-view.现在您可以从列表中选择您刚刚克隆的存储库.
  • 点击Next并选择Import as General Project.现在您有一个 git 存储库来进行 eclipse.
  • 将其转换为 Java 项目:将其他 Java 项目中的 naturebuildCommand 元素添加到您的 .project 文件中:
  • First go to File>Import...>Projects from GIT.
  • In the Select a Git Repository view you first press Clone. And follow instructions. This will create a local "checkout" of the repository to your computer. You can set the folder to be your workspace so it looks like any other of your eclipse projects.
  • After you have cloned the repository you get back to Import-view. Now you can select the repository you just cloned from the list.
  • Click Next and select Import as General Project. Now you have a git repository to eclipse.
  • Convert it to Java project: Add nature and buildCommand elements from other Java project to your .project file:

.project 中的相关部分:

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

然后从 Project>Properties>Java Build Path>Source 添加您的源文件夹(和可能的库).

Then from Project>Properties>Java Build Path>Source add your source folders (and possible libraries).

添加到 Java 项目的转换.

Added the conversion to Java project.

这篇关于如何将 GIT 非 Eclipse Java 项目导入 Eclipse?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆