How to import a non-Eclipse Java GIT project into Eclipse?

I have some problems importing a Java project into my workspace. I follow this tutorial - however, I cannot use the last step of Importing existing projects because I use the GIT repository, which I do not use Eclipse for specific .project and .classpath files.

Use the project wizard

Therefore, the project is not recognized as a project and, therefore, cannot be imported. So I tried my luck using the Use Project Creation Wizard option and select “Java Project” in the next dialog box. The problem is that this creates a new Java project without any content! The project is also not connected to the GIT repository.

Edit: this is a known eGIT error: Error 324145 - Importing a project does not work for certain types of projects - if you want this problem to fix a vote for it ...

Import as a common project

If I use Import as a general project , Eclipse always wants to use the external repository directory as the project directory, which is not what I want, and in addition, the created project does not support Java.

So I ask, why is it so difficult to import a Java project into Eclipse using eGIT?

+43
java git eclipse import egit
Nov 09 '11 at 18:52
source share
5 answers

This is possible by first cloning the repository and then creating a common project on it. Then you can convert it to a Java project. Here's how:

  • First go to File > Import... > Projects from GIT .
  • In the Select a Git Repository view, first click Clone . And follow the instructions. This will create a local “check” of the repository on your computer. You can set the folder in the workspace to look like any other of your eclipse projects.
  • After you cloned the repository, you will return to Import -view. Now you can select the repository that you just cloned from the list.
  • Click Next and select Import as General Project . You now have a git repository for eclipse.
  • Convert it to a Java project: add nature and buildCommand from another Java project to your .project file:

Relevant sections from .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 the source folders (and possible libraries).

Edit: Added conversion to Java project.

+35
Nov 09 '11 at 7:25
source share
— -

With Git (especially EGit), your 2 best options are:

1) Create a java project in eclipse, and then create the linked folder where the source lives in your Git repository (mentioned by @mattb). I don’t think EGit will easily connect to your Git repository in this mode, but your eclipse project files will be in a different place than your original tree.

2) Create your java project and let it specify the external Git repository (which you mentioned). It will create the .project and .classpath file where your source lives. Then, with Team>Share Project you can connect EGit to an existing Git repo.

Option 2 (which I use) allows the tools to work with java projects in the Git repository reliably.

+6
Nov 09 2018-11-11T00:
source share

It may not be applicable to your project, but if you use Maven in a project, you can import it as a Maven Project from Eclipse, if you have m2e installed, thus all the necessary files, such as .project , .classpath . I believe this is a good approach, because if your pom.xml well written, it can contain all the necessary information about the project, such as the assembly of the target directory, classpath, Java version, etc., and probably This will work with most popeler IDEs.

I suggest using Maven for every java project, even for a simple hello world application, because I see it as a kind of “standardization” for Java projects.

+5
Mar 24 '13 at 20:39
source share

Create a new project in eclipse and simply specify the source directory in existing sources, not the default.

+4
Nov 09 '11 at 18:59
source share

here I saw all the methods for importing a project without eclipse in eclipse (open source git projects in eclipse) ... there is no need to copy the .project or .classpath file to copy ... here is the step-by-step process -

Step 1. Import the project from git. Paste the URL and import the project as a shared project.

Step2. If you want to import it as a maven project, you must have the m2e plugin installed in your eclipse (eclipse market).

Step3. Now we have to convert this general project to an eclipse project. Right click on the project -> properties-> ProjectFacets. click the "Convert to form" button

Step4. Now, if your project is a web project. Look at the left side window .. there is a DynamicwebModule option ... check it (leave it if this is not a web project) .... In the right window. Click on the runtimes tab. Now check the server and the JDK version as .. apply Ok.

Step5. If this is a maven project .. then right click on the project congigure-> convert to maven project-> Finish

+4
Sep 27 '15 at 16:10
source share



All Articles