[英]How to import a GIT non-Eclipse Java project into Eclipse?
I have some problems importing a Java project into my workspace. 将Java项目导入我的工作区时遇到一些问题。 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. 我正在学习本教程 - 但是我无法使用最终的Import existing projects步骤,因为我使用的GIT存储库不包含Eclipse特定的
.project
和.classpath
文件。
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.
因此,我尝试使用“ 使用新项目”向导选项并在下一个对话框中选择“Java项目”。 The problem is that this creates a new Java project without any content!
问题是这会创建一个没有任何内容的新Java项目! The project is also not connected to the GIT repository.
该项目也没有连接到GIT存储库。
Edit: 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... 编辑:这是一个已知的eGIT 错误 : 错误324145 - 项目导入不适用于abitary项目类型 - 如果你想要这个问题固定投票...
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. 如果我使用Import作为一般项目, Eclipse总是希望将外部存储库目录用作项目目录,这不是我想要的,另外创建的项目不支持Java。
Therefore I am asking why it is so complicated to import a Java project into Eclipse using eGIT? 因此我想问为什么使用eGIT将Java项目导入Eclipse是如此复杂?
It is possible by first cloning the repository and then creating a General project based on that. 首先可以克隆存储库,然后基于此创建一个General项目。 Then you can convert it to Java project.
然后,您可以将其转换为Java项目。 Here is how:
方法如下:
File
> Import...
> Projects from GIT
. Projects from GIT
转到File
> Import...
> Projects from GIT
。 Select a Git Repository
view you first press Clone
. Select a Git Repository
视图中,首先按Clone
。 And follow instructions. Import
-view. Import
-view。 Now you can select the repository you just cloned from the list. Next
and select Import as General Project
. Next
然后选择Import as General Project
。 Now you have a git repository to eclipse. nature
and buildCommand
elements from other Java project to your .project
file: nature
和buildCommand
元素添加到.project
文件中: Relevant sections from .project
: .project
相关部分:
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Then from Project>Properties>Java Build Path>Source add your source folders (and possible libraries). 然后从Project> Properties> Java Build Path> Source添加源文件夹(和可能的库)。
Edit: Added the conversion to Java project. 编辑:添加到Java项目的转换。
With Git (especially EGit) your 2 best options are: 使用Git(尤其是EGit),您的2个最佳选择是:
1) Create a java project in eclipse, and then create a linked folder to where the source lives in your git repository (mentioned by @mattb). 1)在eclipse中创建一个java项目,然后创建一个链接文件夹到源代码所在的git存储库(由@mattb提到)。 I don't think EGit will connect to your git repo easily in this mode, but your eclipse specific project files will be in a different location than your source tree.
我不认为EGit会在这种模式下轻松连接到你的git repo,但你的eclipse特定项目文件将位于与源树不同的位置。
2) Create your java project and let it point to the external git repo (which you mentioned). 2)创建你的java项目,让它指向外部git repo(你提到过)。 It will create a .project and .classpath file where your source lives.
它将创建一个.project和.classpath文件,其中包含源代码。 Then using
Team>Share Project
will allow you to connect EGit to the already existing git repo. 然后使用
Team>Share Project
将允许您将EGit连接到现有的git仓库。
Option 2 (which I use) allows the tools to work with java projects in a git repo reliably. 选项2(我使用)允许工具可靠地使用git仓库中的Java项目。
May not be applicable to your project but if you are using Maven in the project, you can import it as Maven Project
from Eclipse if you have m2e
installed, this way all the needed files like .project
, .classpath
will be generated. 可能不适用于您的项目但如果您在项目中使用Maven,如果您安装了
m2e
,则可以从Eclipse导入Maven Project
,这样就可以生成所有需要的文件,如.project
, .classpath
。 I think that is a good approach because if your pom.xml
is well-written, it can contain all the needed information about the project such as build target directory, classpath, java version etc., and it will probably work with most of the populer IDEs. 我认为这是一个很好的方法,因为如果您的
pom.xml
编写得很好,它可以包含有关项目的所有必需信息,例如构建目标目录,类路径,Java版本等,它可能适用于大多数populer IDE。
I suggest to get used to use Maven on every java project, even for a simple hello world application because I see it as some sort of "standardization" for Java projects. 我建议习惯在每个java项目上使用Maven,甚至是一个简单的hello world应用程序,因为我认为它是Java项目的某种“标准化”。
here I saw all methods to import a non eclipse project into eclipse(open source git projects into eclipse) ... no need to copy .project or .classpath file to copy ... here is the step by step process- 在这里,我看到了将非eclipse项目导入eclipse的所有方法(开源git项目进入eclipse)...无需复制.project或.classpath文件进行复制......这里是一步一步的过程 -
Step 1. import the project from git. 步骤1.从git导入项目。 Paste the URL and import the project as a general project.
粘贴URL并将项目作为常规项目导入。
Step2. 第2步。 If you want to import it as a maven project you should have m2e plugin installed in your eclipse(eclipse marketplace).
如果你想将它作为maven项目导入,你应该在你的eclipse(eclipse市场)中安装m2e插件。
Step3. 第三步。 Now we should convert this general project into eclipse project.So right click on project ->properties->ProjectFacets.
现在我们应该将这个通用项目转换为eclipse项目。所以右键单击项目 - > properties-> ProjectFacets。 click on ConverttoFacetedform
单击ConverttoFacetedform
Step4. 第4步。 Now if your project is a web project.See the left side window.. there is an option DynamicwebModule ... check it (leave it if it's not a webproject).... On the rightside window .. go to runtimes tab.
现在,如果您的项目是一个Web项目。请参阅左侧窗口..有一个选项DynamicwebModule ...检查它(如果它不是webproject则保留它)....在右侧窗口...转到运行时选项卡。 Now check the server and JDK version both.. apply Ok.
现在检查服务器和JDK版本..应用确定。
Step5. 第五步。 If it's a maven project .. then right click on project congigure->convert to maven project->Finish
如果它是一个maven项目..然后右键单击项目congigure->转换为maven项目 - >完成
在eclipse中创建一个新项目,只需将源目录指向现有源,而不是默认路径。
Steps: 脚步:
It will convert your simple git project to simple java project of Eclipse. 它会将您的简单git项目转换为Eclipse的简单Java项目。
-- Happy coding :) - 快乐编码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.