Import Maven projects in Eclipse from Git repo - eclipse

How do I import Maven projects in Eclipse from Git repository?
My setup:
Eclipse Neon
EGit with SSH, using built-in PPK auth
EGit connector for project import installed
Git repository with 120+ Maven projects
I finally managed to clone my 16+ GB Git repository. Now I wonder, how am I supposed to work with my projects in Eclipse.
In Git Repository view, I see a folder called 'Working Tree' containing all the project folders. Having the EGit connector installed, the context menu contains an entry 'Import Maven Projects...'. There I selected the pom.xml files of my Maven projects (no other file types are shown) and after a while Eclipse has created projects in the Project Explorer view accordingly.
However, the projects only contain the pom.xml file and none of the actual code files or folders.
Did I miss something? How do I create Maven projects automatically in Eclipse for all the Maven projects that are in my Git repo?

Eventually, it turned out that Eclipse did a faulty import on first attempt. In despair I deleted all projects that were created by the importer (without deleting the files on disk), then I ran the import again using the context menu entry Import Maven Projects... of the Git view.
This time all projects were created fully, not just containing the pom.xml file but all Java packages, source files and additional binary resources as well.
I'm not sure if the first attempt to import just failed or if the fact, that I eventually ran the importer twice, fixed the problem. But maybe my experiences will still help someone else:
In case of similar problems, try deleting the empty projects and simply run the import again.

Related

How to import projects properly using Git from cloud

How to properly import projects from BitBucket or another cloud repository? I have Eclipse Neon JavaEE. Even if there is Git preinstalled yet and (for my purposes important) Maven too. The imported projects are not real projects.
The straighforward way is:
File -> Import -> Git -> Clone URI (copied from repository i.e.
BitBucket)
Fill in username/password if needed
Next
Now I can see this picture (Ubuntu Linux 16.04)
But no any from this options clone huge of projects properly.
To successful clone projects I must in this moment
Cancel process (cloning is in local repository yet)
and manually add projects one after another one into workspace in Git Perspective on expanded Working tree using
Right click on projects -> Import Projects...
Do you know anybody how do this operation better?
Next another thing is, that I cannot select more projects, because the option Import Projects... will disappear.
Another approach is to:
clone those repositories manually in command-line (with a Git you install yourself, separately from the one used by Eclipse).
Clone those repo in any path you want, outside of the Eclipse workspace folder.
import the project you want into the Eclipse workspace, by using the local path where the Git repo has just been cloned.
once imported, select the Team/share option by right-clicking on the imported project in Eclipse: it should recognized the project is already shared as a Git repo.
That wy, you don't try to do everything with Eclipse in one Go: you separate and keep better control on each step (clone, import, share)

Connect existing Eclipse project to existing Git repository

I have an Eclipse workspace in ~/EclipseWorkspaces/Sabia with a number of projects under Ubuntu 15.10. The source code for these projects resides in a Git repository at ~/GitRepositories/Sabia.
I can find no way to tell Eclipse in the Pydev Package Explorer that the projects use the Git Repository. If I try to use Team->Share, the system rejects the Git repository because a directory for each project exists in the repository and Eclipse is trying to move the project to the repository which already has a project directory.
I tried the suggestion by Michal Grzejszczak but unfortunately it does not work because the Git Repository does not contain complete projects, only the source trees for the projects. The Eclipse metadata is in /EclipseWorkspaces, not in the Git Repository so import projects on the Git Repository perspective does not work.
In addition when I tried to delete the projects I got the following error message:
AppFrame (One of my projects) contains resources that are not in sync with /home/jonathan/Dropbox/EclipseWorkspaces/Sabia/AppFrame. Press 'Continue' to force delete`
for half of my projects.
Unfortunately the message gives no more information and I have no idea what kind of problem might actually exist. I am not prepared to delete any flawed projects until I have corrected whatever was wrong.
How can I tell the Eclipse Pydev Package Explorer where the Git repository resides?
You need to first add this repository to Git repositories view in Eclipse. Then remove these project from workspace, but without deleting contents and then the most crucial part import them back with "Import projects..." from context menu after right clicking Working tree of the repo in Git repositories view.
That should make your projects managed by Git.

Imported repo does not import the projects within

the title says most of it. I also checked the "Import all existing Eclipse projects after clone finishes". I am starting to learn github. Please help me and make this a pleasent start so I actually keep using it. The repo folder that I had to choose for the repo is not in my eclipse workspace. I thought I don't need to manually import the projects in the repo if I check that checkbox. I use eclipse Mars and EGit.
Edit: I created a new repository before on GitHub. I imported a test project into my repository to play around with it and test stuff. Thats all whats in the repository.
Thats what my GitHub repo looks like on the website:
Apprecciate your help.
Eclipse will only import Eclipse projects. So if you have some plain Java projects (without Eclipse specific meta data) or even just plain folders in your repository, those will not be imported. However, you can import all such non Eclipse artifacts into Eclipse projects by using the "Import -> General" wizard category.
And in case your projects are Eclipse projects, you can re-try the import from the locally cloned repository into your workspace by using the "Import projects" menu on the repository in the repository view of Eclipse.

not able to import github project in eclipse

just created project on github from my office and when then i came home and was trying to import the project on my home machine but I am not able to do it.
Following is the detail.
Both home and office machine has eclipse Juno and Egit plugin installed. I am able to do check-in from office. but at home I am not even able to import the project.
my workspace directory - c:\gaurang
git local directory - d:\Gaurang\Webdriver-Data-Driven-Framework
Now if i choose "Import existing projects" it says No project found
if i choose "Use the new Project Wizard" - it creates empty project
if i choose "Import as general project" - it creates the project but not a java project so not able to compile or run.
My git repository - https://github.com/Gaurang033/Webdriver-Data-Driven-Framework.git
I struggled in a similar fashion when checking out https://github.com/angular/angular-seed.git
The problem was that I expected to happen in a single step. The Github project does not contain eclipse files, so of course you can not import existing projects - the other options should work, however and they don't
The solution for me was to:
Clone the github repository locally e.g. /home/name/git/angular-seed (import.../Projects from Git/URI)
Obtain a working copy as a plain project (import.../Projects from Git/local)
I think it's a bug
The result is that I have the cloned repository in /home/name/git/angular-seed and a skeleton project with a ".project" file that points to that place
You have to push your .project and .classpath files to the repository if you want to be able to import the project using the "Import existing projects" wizard. If those are not present, eclipse cannot detect an existing java project.

Importing a Maven project into Eclipse from Git

How can I get the effect of choosing to import from both Maven and Git and have Eclipse properly generate my project?
To get my project into Eclipse I can choose File->import->maven and then I get all the Maven projects imported and can build fine, or I can choose File->import->git and make a new project that ignores the pom.xml and does not generate the project properly.
It seems I can do one or the other but not combine both so I get a correctly generated project.
Eclipse Indigo + M2Eclipse 1.0 makes it very easy.
If you don't already have the Git connector for M2Eclipse install it. M2Eclipse will help you along by prompting you on the Import menu.
Select the "Import..." context menu from the Package Explorer view
Select "Check out Maven projects from SCM" option under the Maven category
On the window that is presented choose the link "Find more SCM connectors in the m2e Marketplace
Find connector for Git...install...restart
Note that in the search box you may have to enter "EGit" instead of "Git" to find the right connector.
With that done, simply go to the EGit repository, bring up the context menu for the Working directory and select "Import Maven projects...".
Done!
I would perform a git clone via the command line (outside Eclipse) then use File -> Import... -> Existing Maven Projects.
Your projects will be understood as using Git and Maven. It's the fastest and most reliable way to import IMO.
Step 1 : Setting Up Eclipse
First of all you'll need to have a few Eclipse plug-ins installed. So use eclipse IDE software install feature in the help dropdown menu → Install new software, and add link to Available Software Site, then install it.
GIT plugin (EGIT)- http://download.eclipse.org/egit/updates
Eclipse Maven plugin (M2Eclipse) - http://download.eclipse.org/technology/m2e/releases
Maven SCM Handler for EGit (m2e-egit)
Install from the M2E Marketplace (Settings → Maven → Discovery → Open Catalog and search for " m2e-egit")
Step 2 : Clone the repository
Clone(download) your Maven Projects from Git
Check out non-eclipse Maven Projects from Git (File → Import.. → Maven → Check out Maven Projects from SCM)
Now add your git repository link to SCM URI field.Then click next & finish.
As of this (updated) writing, a working setup is the following:
Eclipse 3.8 (Eclipse Indigo update site)
EGit 1.3.0 (Eclipse Indigo update site)
m2e 1.0.200 (Eclipse Indigo update site)
m2e-egit 0.14.0 (m2e marketplace when adding a connector)
Tested on Ubuntu Raring.
You can certainly "Import" -> "Maven" -> "Check out Maven Projects from SCM", and this is the quickest way. However, such direct import currently does not give you control over the cloned repository folder name. You may be better off working from the "Git Repository" View and perform either a "Clone from a Git Repository and add the clone to this view", followed by an "Import Maven Projects" from such clone; the longest way would be to do your manual cloning and then "Add an existing local Git Repository to this view", followed again by an "Import Maven Projects". Either case you have full control on the cloned folder.
A final comment on a side issue that made me cry in frustration. As far as I know, if the cloned repository lies on the root of your Eclipse workspace, and your Maven project file hierarchy has a POM on its root, then importing such root project will rename the cloned folder (with the template you chose, defaults to [artifactId]). Without changing your project structure and without keeping files outside your workspace, you can easily work around this issue by cloning on a subsubfolder of the workspace folder.
I have been testing this out for my project.
Eclispe Indigo
"Help > Install New Software" Enable/Install official Git plug-ins at "Eclipse Git Plugin .." and install the lot.
Enable the Maven/EGit connector with these instructions How do you get git integration working with m2eclipse?
Switch to the Git Repository perspective. Right click paste the project git url. The defaults should all work. You may want to change the install folder it guesses.
Expand the cloned repository and right click on "Working Tree" and pick "Import Maven Projects...".
Switch to the Java perspective. Right click on the project and choose "Team > Share Project". Select "Git" and be sure to tick the box "Use or create repository in parent folder of project".
Here's my workaround, this is a solution to these issues:
You can't install m2e-egit (I get an error in Juno)
Converting a general project (connected to your Git repository) to a Maven project isn't working for you (The Import Maven Projects step seems essential)
Importing Maven Projects from your repository on the filesystem isn't showing the project connected to Git.
Setup your Git repository in the Git Repository Exploring perspective.
Switch to the Java perspective, Import > Existing Maven Projects
Browse to your Git checkout in the filesystem, select the directory containing the pom.xml file. Finish the import;
you'll notice these projects aren't connected to Git. :-(
Delete these projects, but DO NOT DELETE FROM FILESYSTEM.
We don't want our clone deleted; this task also leaves the .project file behind so that we can import in the next step.
Go back to the Git Repository Exploring perspective.
Right-click your repository, Import Projects...
Select Import existing projects
In the explorer below, browse to and select the directory containing the pom.xml (and .project file) , then click next.
Continue through the wizard.
Import without installing any additional connectors for Mylyn:
Open Git Repositories view (Window->Show view->Git Repositories)
Press Clone a Git Repository button and proceed with all steps
In newly created repository expand Working Directory, right click on folder with your project and select Import Projects. Then either choose Import existing projects, or select Import as general project. If needed after importing right click on your project and select Configure->Convert to Maven Project (and Maven->Update Project).
You should note that putting generated metadata under version control (let it be git or any other scm), is not a very good idea if there are more than one developer working on the codebase. Two developers may have a totally different project or classpath setup. Just as a heads up in case you intends to share the code at some time...
I have a maven project with three submodules that is managed in git. I set them up in eclipse as follows:
I registered the git repository with eclipse using EGit
I imported the projects as existing Maven Projects
For each project, I went Team | Share Project.
Direct answer: Go to Files>>Import>>Git>>Project From Git (you should have GIT installed on Eclips)
I would prefer to import projects into Eclipse as maven projects rather than git project. Doing this will still allow the project contents to be recognized as git contents. You can continue to perform git operations from Eclipse. As you have mentioned the reverse is not true.
The nature of a project in Eclipse is not based on the SCM which holds the project, but on the type of project - whether war or jar, etc. - which is automagically determined when the project is imported as maven project.
I would be hesitant to check-in to SCM IDE-specific metadata. Doing so assumes a lot of things - all developers are using the same IDE or version of the IDE, perhaps same version of JDK/JRE, that they continue to use the same version throughout the project lifecycle and so on.
Can't you import it as a git project and then (if you have the m2eclipse installed) right click on the project in the Package Explorer > Maven > Enable Dependency Management?
After checking out my branch in Egit, I switched to the Java View, then used File-->Import, Git-->Projects from Git, then selected the top level maven directory. This was with Eclipse Kepler.
Instead of constantly generating project metadata via import->maven command, you can generate your project metadata once and the place it in your git repository along with the rest of your source code. After than, using import->git command will import a proper maven-enabled project, assuming you have maven tools installed.
Make sure to place into the source control system all files in project dir that start with '.' such as .classpath and .project along with the entire contents of the .settings directory.