Eclipse project facets in Maven projects - eclipse

I'm starting to work with Maven in Eclipse but when I create a Maven project with several children projects, let's say:
-Maven project
-Web project
-EJB project
-JSF project
Each of the children projects has a different set of facets in order for Eclipse enable the corresponding tooling.
The problem is that, when I import the Maven project, the children projects exists in the workspace (under the Maven project) as simple folders, so, no specific-tooling is available.
What is the correct way to work with Maven in Eclipse?

You need to "Import...>Existing Maven project". The import wizard will recursively discover all child modules (assuming they all have a pom.xml) and import them properly as separate Eclipse projects

Related

Maven modules projects no longer showing as maven project inside the parent project

I have this parent Maven project and inside it I have 6 modules, It was created on Eclipse Neon and there everything is showing correct regarding the project structure.
The problem is after putting the project on a SVN repository and importing in another Eclipse, in this case, all the modules inside the parent project no longer show as maven project but just a normal folder.
What could be wrong? Anything on Eclipse? Any plugin? This Eclipse with the wrong view is the latest one, java-2019-09.
I need ideas :)
Edit 1:
Edit 2:
To import the nested projects use File > Open Projects from File System... and choose as Import source the directory of the (already imported) parent project.
By the way, the parent project should be a General Maven project instead of a Java Maven project.

Multi-module Maven with Profile in Eclipse Doesn't Resolve Dependencies on Children

For my setup, I have profiles defined in my ~/.m2/settings.xml, where the profiles define some project-specific repositories. From the command line, I can successfully build the projects using -PprofileHere. However, the profile isn't enabled automatically (i.e. activeByDefault is not set to true for the profile).
In Eclipse 4.5.1 (Mars 1) with m2e 1.6.2.20150902-0002, I import the projects using Import → Maven → Existing Maven Projects. I select the parent project and Eclipse imports them. The children projects are imported, but as expected, their dependencies aren't correctly resolved. To attempt to fix this, I select the parent project, right-click Maven → Select Maven Profiles... and select the correct profile for the parent. I then do the m2e tango by trying various combinations of the following:
Cleaning and rebuilding the project (Project → Clean...)
Updating the parent project (Right-click, Maven → Update Project...)
Updating the children projects (ditto)
Restarting Eclipse
Eclipse continuously shows the dependencies unresolved on the children projects when viewing the children pom.xml's or opening a class in a child module with unresolved dependencies. The only workaround I've found is by enabling the profile automatically in my ~/.m2/settings.xml. Then and only then does Eclipse properly resolve the Maven dependencies.
What am I doing wrong when originally importing / configuring projects in Eclipse?
How it worked for me in a sample project providing the same scenario: make Eclipse use a profile by default for a Maven build.
Right click on the concerned project > Properties > Maven
Type your profile there, it will be used by Eclipse during the build
I never used this option, but apparently its purpose should suit your need.

Checking out hierarchical Maven project in Eclipse

I have checked out using subversion/subclipse a hierarchical maven project into my Eclipse project.
At first it is a plain folder structure, then I right click->Configure..->Convert to Maven Project.
Now the top node is a Maven project, however all the sub nodes are not recognised as maven projects. I have tried Maven->install and nothing happens.
You have to import the projects as maven projects.
just right-click the package explorer and Import... > Maven projects
to import an existing maven project into Eclipse.
I realise the mistake was that I checked out one level too high. Instead of checking out the root node, I checked out the folder above it.
So in that case Eclipse created a POM file for me for that directory, which confused me into thinking that was the parent POM.
Notice how there is a question mark on the top level POM? It is not in SVN yet.

Maven Multiple module project in Eclipse issue

I have multiple module maven project which i imported in eclipse.
mvn eclipse:eclipse
and it shows child modules as following.
problem is it is not recognizing any of the child modules java files. if hover objects it does not show up any thing and consider as plain text files. it complains that it is not in build path ???
any idea how to fix or how to import multip modules maven project in eclipse.
Maven support is included in Eclipse Kepler. You can find it in the File -> Import screen as Maven -> Existing Maven Projects.
Selecting a directory with a parent POM in it will prompt you to import all its children as well.
If you really want to go down thatroad check out this old school method with eclipse:eclipse and multi-module import plugin.
But I have a different suggestion. Remove all eclipse:eclipse generated files, download m2e (new versions of Eclipse already include it). Then just use m2e Import Maven Project feature. It will recognize nested pom.xml files and let you create separate projects out of the ones you choose to work with.
Source: m2eclipse-book

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