How to import a maven project from SVN tags into eclipse? - eclipse

(This may be a dumb question but I am not quite familiar with the interesting eclipse importing logic)
I am trying to read the source code of Netty, so I checkout the tag folder for Netty-4.0.24.Final from the Netty SVN (https://github.com/netty/netty).
The files are shown as below:
Since there's a pom.xml files there, I use the "import existing maven project" to import it into Eclipse.
But the imported result looks like this:
I am expecting some well-formatted package layout. What's wrong?
ADD 1
I found this thread: "Source folder is not a Java project" error in eclipse
It seems I need to manually turn on the Java Project Facet for each project in order to see source code organized in packages. But I am wondering does it have to be this tedious? Is there any simpler way to import a maven project and display it in packages?

It doesn't matter if you are using tag or latest branch, Netty project composed from a sub-projects you see in the worskpace
Yes each one is full Maven project on it's own and gets deployed as separate artifact into Maven repo. When you open any of them, there will be your familiar Maven folder structure.
Your highlighted pom.xml is multi-module project for all the sub-projects.
It's used to build all sub-projects in one go.
If want to get familiar with this concept: I would suggest this tutorial:
http://books.sonatype.com/mvnex-book/reference/multimodule.html
BTW, when you import sub-projects into Eclipse M2E plugin names projects according their artifact names, not according folder structure.

Related

Importing multimodule maven project from Git into Eclipse/STS

I have been desperately trying to import a multimodule maven project from GIT into my (freshly installed) STS 3.9.4.
During the last hours I tried lots of solutions that were posted on stack overflow, but none of them worked for me.
These are the steps I did:
git cloned the repo from the command line (intentionally, because it didn't work either when I used the GIT integration of STS)
imported the project via File / Import / Maven / Existing Maven Projects
After the project was imported, it looks like this:
(please ignore the red icon at the top left, the problems persists even when this icon is not there)
I can Run As / Maven Install any pom.xml, but when I try to edit java sourcecode Eclipse tells me The resource is not on the build path of a Java project.
To fix this I tried:
convert to faceted form
added Java nature
Configure Build Path / Set as source folder
add buildcommand org.eclipse.jdt.core.javabuilder to .project
Being able to build is fine, but editing sourcecode without support for Organize Imports, Format Source, and so on is a real pain.
From your screenshot I assume the modules are nested within the directory of the reactor pom(=parent pom) and you have imported all of them as projects (reactor and modules).
Don't add a java builder to the "reactor" project.
Make sure not to open the java files from the projects corresponding to the reactor pom, but from src folder within the corresponding module projects.
The solution to this problem was somehow hidden, but in the end I have to say the reason was clear.
After I checked with a different multimodule project (https://github.com/Activiti/Activiti.git), I was sure that my STS and other components don't suffer from a generic problem. So the cause must be located in the project itself.
The multimodule project was setup correctly on the pom.xml level. But the topmost pom.xml was modified: most of the modules had been commented out:
The developer who introduced that change didn't experience any problems because he kept his already existing workspace. And the problem only occurs when a new workspace gets created and maven scans the pom files.

are there different ways of importing git repository to Eclipse?

Why when I import a git project it does not appear like full package path view (main.java.comformance) like this image:
I have imported this project before but now in the package view, it only appears as a tree of folders and not full package path view like main.java.comformance with package icons. I wonder what I'm doing differently now. I followed the instructions in this video: https://www.youtube.com/watch?v=L8IeaWHZCRo)?
Both projects on the screenshot do not seem to be configured correctly (probably because they were not created with Eclipse or files like .project were not shared):
The project on the right side is obviously a Maven project (with probably this pom.xml file): the Java source folder should be src/main/java/ (default of Maven) instead of src (default of Eclipse) and the Java packages for instance uk.ac.manchester.cs.jfact instead of main.java.uk.ac.manchester.cs.jfact.
The project on the left side is not even configured as a Java project.
The simplest way is to use the Eclipse Smart Import feature (instead of configure everything manually): the Java nature of the project will be detected even without the .project file and also the pom.xml file is read to get the required JARs and to configure the Java build path and source folder(s) automatically:
Clone the Git repository
In the Git Repositories view right-click the Working Tree node and choose Import Projects...
Do you see the "J" in the icon next to the project name "jfact" at the right image?
That means that it is a "java" project. Eclipse does not know anything about your project.
You will have to do one of this:
Checkout the project again with Eclipse and use a "wizard" configuring it as a java project.
Enable Project Facets (right-click on the project name), and then enable "Java" in the Project Properties/Facets. This is not trivial, so I don't recommend this. - If this is a solution, actually I don't know for sure -
If you are using maven, close the project and execute mvn eclipse:eclipse to convert/create the project files for eclipse, and open again the project.
After you manage it to become a Java project, furter steps could be needed, but maybe will be enough.

How to import a gitlab project to eclipse as a maven project?

I want to import it to eclipse as a maven project .i want to know it from very first step? any sources?
The first step is to import your GitLab "project" (meaning a repo cloned from a GitLab server) into your Eclipse workspace.
If it is a java project, then you can use a plugin like "eclipse-to-maven" to convert that project to maven:
Converts .classpath files into pom.xml
If required, prints the dependency graph of eclipse projects.
Moves source folders according to Maven convention. So for instance Java sources go to src/main/java folder.
Removes spaces in the names of the folders. So "Calculator Component" becomes "CalculatorComponent"
Other manual conversions are described in "Convert Existing Eclipse Project to Maven Project".

Maven eclipse - mutli project dependencies not appearing

I have a bunch of maven projects which all are part of a parent project. When I import the parent project into eclipse, I was expecting the child projects source folders to be listed in my parent project, however they are not. They also don't appear in the "Maven Dependencies" section.
Is this the correct behavior or am I missing something. If it is the correct behavior, then what is the best practice around doing this?
Should I be importing each project into eclipse and then editing the build path for my parent project to include them all? I really don't like this approach because I want to do everything through maven.
Note: I am not using mvn eclipse:eclipse to generate my project files, I am using the maven plugin directly in eclipse IDE as: Import existing maven projects
Thanks!
Import your parent project then close it (right click on the project in the package explorer > close project). Select it and go to file > import > maven > existing maven projets here you should see the list of the child projects, select the wanted ones then finish.
Now in your package explorer you should have :
A project parent-project where you work on the pom-parent and eventually on the src-parent
One project per child-project where you work on the corresponding pom-child and src-child
If some dependencies are missing try to update the projects (right click on the projects in the package explorer maven > update project)
Normally you don't have to edit the build path in eclipse it must be handle by the maven nature of the project (the maven nature is often represent by a M on the icons of the projects)
Normally, if you don't import "dependencies" projects, Eclipse simply uses the jars presents in your local repo (.m2).
However, I don't get what you mean by "I have a bunch of maven projects which all are part of a parent project".
Projects are not part of each other. And the child projects sources should not be listed in the sources folders. You only uses the bytecode.
If you want to "see all your sources" :
However, you can have a complete "view" of the code if you export your sources as sources jars.
If you want to be able to debug across your projects :
You then have to import all your projects in Eclipse. If a project is closed, Eclipse will use the jar like if the project was not there. If the project is open, it will use the project (not sure exactly how, but it works smoothly).

Eclipse + Maven + Git + Multi-Module projects = Unhappiness

We've got a multi-module project using Eclipse and Maven. The only way I could get it to work in the past was to use a flat layout for the projects, where the parent module was a peer to the other modules. This worked fine with m2eclipse and Subversion.
Now we'd like to move to Git and GitHub. I'd like to expose the entire project, along with all the modules, as a single project on GitHub. The problem is that EGit, the Eclipse/Git plugin, wants to manage projects one at a time, not groups of projects, and so if you've got a flat layout, you can't do it.
The right answer is to use a standard Maven hierarchical layout and manage the parent and all the modules as a unit. But Eclipse doesn't like that, and no amount of fiddling will get Eclipse to accept nested projects. m2Eclipse does not support hierarchies: https://issues.sonatype.org/browse/MNGECLIPSE-2291
So what do you do? Do Git from the command line and abandon the ability to see what files have changed in Eclipse? Or abandon Eclipse?
A standard Maven multi-module structure as a single git repo works perfectly fine for me in Eclipse Indigo with M2e and the git plugin that shows up in that environment. You can't ask Eclipse to do your fetching for you, but once you've pulled from command line, you use Team/Share, say 'Git!' and all is well.
I think I see what's the source: hierarchy is a problem for projects inside the workspace, not 'existing projects' that you import.
Here's a typical workflow:
use git svn clone to get a tree. it's a stock, hierarchical mvn multi-module tree
in eclipse, use import/maven/existing maven project. Point at the whole tree
select all
OK
it works fine. The nesting does not disturb eclipse one bit. I don't know what problem that bz is pointing at.
Before I used m2e I used the maven-eclipse-plugin. And it also worked in these cases, because it does not generate a .project/.classpath for <packaging>pom</packaging> aggregating projects, so Eclipse is never called upon to actually nest anything.
I'm not alone -- see the developer setup instructions as cxf.apache.org for an open source example that you can try for yourself.
Is it possible that you are working with old versions of the tool?
I have a Maven multi-module project that I work with using Eclipse 3.7 (Indigo), M2Eclipse (1.0) and EGit (1.0).
On the file system the multi-module project has a single parent directory.
In Eclipse I have separate projects for each module.
M2Eclipse does the dependency management perfectly.
There is single git repository (.git directory) at the top-level and EGit works perfectly.
You can put your modules in Git with hierarchical layout. And build those modules by Maven. If those modules are projects(whatever java, c++ or php project) recognized by Eclipse, they can be imported into workspace as flat layout in workspace.
-- the root of Git working directory
-- moudule1
-- project1(a java project)
-- .project(a project file recognized by eclipse JDT)
-- pom.xml
-- project2(a java project)
-- .project
-- pom.xml
-- module2
-- projectA(a java project)
-- .project(a project file recognized by eclipse JDT)
-- pom.xml
-- projectB(a c++ project)
-- .project(a project file recognized by CDT)
-- pom.xml
For Maven projects, multiple imports at once can be achieved via the Maven import wizard (that is accessible from Git).
In case you don't know what kind of projects you're about to import, you can use the new Easymport that will import project "as best", by deducing configurations from various files. See https://github.com/jbosstools/jbosstools-playground#easymport-easy-and-smart-openimport-of-a-project
Once you get all those projects, you can use the Nestor plugin, which will show project in a nested/hierarchical layout, mapping more correctly your Maven project: https://github.com/jbosstools/jbosstools-playground#nestor-view-nested-projects