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

40,738

Solution 1

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.

Solution 2

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.

Solution 3

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

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.

Solution 4

Create a new project in eclipse and just point the source directory at the existing sources, rather than the default path.

Solution 5

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-

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

Step2. If you want to import it as a maven project you should have m2e plugin installed in your eclipse(eclipse marketplace).

Step3. Now we should convert this general project into eclipse project.So right click on project ->properties->ProjectFacets. click on ConverttoFacetedform

Step4. 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. Now check the server and JDK version both.. apply Ok.

Step5. If it's a maven project .. then right click on project congigure->convert to maven project->Finish

Share:
40,738

Related videos on Youtube

Robert
Author by

Robert

-

Updated on July 09, 2022

Comments

  • Robert
    Robert almost 2 years

    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?

  • Robert
    Robert over 12 years
    I would prefer having one directory per project inside my workspace. Otherwise I would have to remember where each project is located in the file-system when I need to access the directory directly which happens very often because Eclipse isn't working well as a Explorer alternative.
  • matt b
    matt b over 12 years
    so then just create the default location and copy the source over?
  • Robert
    Robert over 12 years
    Option 2 is a nice idea - however eGit does not allow to share a project into the root of a repository (where the cloned files are located). Therefore it allows only to share the project as a subdirectory :(
  • Paul Webster
    Paul Webster over 12 years
    That might be true, all of the projects I'm working with are of the form <repoDir>/bundle/project(s).
  • JPM
    JPM almost 12 years
    If I could give you 10 upvotes I would, thanks this did the trick for me.
  • cinnamon toast
    cinnamon toast about 11 years
    where do you see the "Clone" in Select a Git Repository view? I only see Local and URL.
  • raffian
    raffian over 10 years
    @cinnamontoast I was looking for the 'Clone' button to in that dialog, any ideas?
  • raffian
    raffian over 10 years
    In step 2, am I selecting from a remote git, or from a local repository?
  • raffian
    raffian over 10 years
    Maybe I'm missing something, but with option 2, I create a java project in my eclipse workspace, then use Share Project to connect to local git repo under C:/Users/raffian/git, that's fine, but after finishing, eclipse moves the project from eclipses' workspace to reside under the local git repo; is that normal? I don't feel comfortable working directly in the repo folders.
  • Paul Webster
    Paul Webster over 10 years
    Yes, that's normal. Working on your project while it is under the git repo working tree is the best way to do it. That's how our own repos are organized: git.eclipse.org/c/platform/eclipse.platform.ui.git/tree
  • benvolioT
    benvolioT over 10 years
    When I follow these instructions using a local repo, I get this error "overlaps the location of another project" on step 4 of your instructions. Any tips? Edit: see stackoverflow.com/a/9463023/87696.
  • jmarcosSF
    jmarcosSF about 9 years
    These steps work fine, yet to configure as a Java Project within Eclipse, I would go Project>Properties>Project Facets, check the "Java" Project Facet, Apply and OK.
  • 王奕然
    王奕然 about 9 years
    should also add .classpath file