Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

Use the New Projects wizard

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.

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...

Import as general Project

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.

Therefore I am asking why it is so complicated to import a Java project into Eclipse using eGIT?

like image 285
Robert Avatar asked Nov 09 '11 18:11

Robert


People also ask

Can I import a Git project into Eclipse?

Open Eclipse and choose Import –> Projects from Git (with smart import) Choose the Clone URI option in the Git import wizard and click Next. Confirm the URI, Host and Repository path parameters and click Next. Choose the Git branches to clone from the remote repository and click Next.

How do I export a Java project from GitHub to Eclipse?

Step 1: Open Eclipse IDE and right-click on the project you want to push and go to Team->share project. Step 2: It will add the project to the given repository as shown below: Step 3: Again right-click on the project and go to Team->commit.


2 Answers

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:

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

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 your source folders (and possible libraries).

Edit: Added the conversion to Java project.

like image 159
Lycha Avatar answered Sep 22 '22 19:09

Lycha


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

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). 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.

2) Create your java project and let it point to the external git repo (which you mentioned). It will create a .project and .classpath file where your source lives. Then using Team>Share Project will allow you to connect EGit to the already existing git repo.

Option 2 (which I use) allows the tools to work with java projects in a git repo reliably.

like image 30
Paul Webster Avatar answered Sep 22 '22 19:09

Paul Webster