Luigi Cortese
Luigi Cortese

Reputation: 11141

How to import a GitHub hosted project as a Java Project in Eclipse?

I have forked this project on my GitHub:

and now I'm trying to import (clone) my own origin repo locally. I managed to do it via Bash command line, but I'm not being able to import the project in Eclipse and make it a "Java Project". It's imported as a "Generic project" where packages are seen as plain directories:

enter image description here

The import wizard gives these 3 options:

enter image description here

If I go with the first one it says "No projects found" and if I go with the second I have no idea how to proceed.

Is this the wrong way to go? I'm using Eclipse Mars (4.5.1) with EGit plugin.

Upvotes: 4

Views: 938

Answers (2)

Tunaki
Tunaki

Reputation: 137319

What you are trying to import is actually a Maven project. First of all, make sure you have M2Eclipse installed, so that the projects can be imported and built automatically.

What I usually do in those cases is the following (pictures are taken with Eclipse Mars 4.5.1, you will need to adjust with your Eclipse installation but it shouldn't change much):

  • Clone the Git repository with the URL: https://github.com/iluwatar/java-design-patterns.git.

    enter image description here

  • Select the master branch only

    enter image description here

  • Once Eclipse has downloaded everything, I do not use the import facility but instead let Eclipse finish and do nothing.

    enter image description here

At this point, there are 2 approaches possible. The repository is checked out into your machine, and the projects need to be imported in Eclipse as Maven projects.

Solution 1: Import as Maven project from the Git perspective

NOTE: this solution requires the m2e-egit connector to be installed. Refer to this answer to locate and install it. The connector will be located at the bottom of the list, below the "m2e Team providers" section, and is named m2e-egit.

  • Still in the Git perspective, expand the Git repository, right-click "Working Tree", and select "Import Maven Projects..."

    enter image description here

Solution 2: Import as Maven project from the Import facility

  • Go to "File > Import... > Existing Maven Projects".

    enter image description here

In both of those cases, you will be greeted with the following dialog, where you can select all the Maven projects you just downloaded and import them.

enter image description here

Upvotes: 6

asgs
asgs

Reputation: 3984

Since your project seems to be using pom.xml, use Maven's eclipse plugin to create an Eclipse project.

Upvotes: 0

Related Questions