Updating the parent Maven project in Eclipse - eclipse

I have a parent Maven project, with packaging set to pom. This Maven project has a few child modules. Today I had a need to delete one of the child modules. I answered OK to Delete project contents on disk (cannot be undone). The entire child Maven module was deleted from the file system, as expected. However, the parent Maven project pom.xml continues to list the deleted module in its modules element, even after the Maven --> Update Project operation is performed.
At present the only alternative that I have is manually updating the parent Maven project pom.xml.
Q) How to enable automatic update of the parent Maven project when one of its child modules is deleted?

Related

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 Eclipse Plugin Doesn't Create Project Dependencies Properly

Suppose I have a top level maven project with two modules:
moduleA
moduleB
and a groupId of my.group.
running mvn eclipse:eclipse on the parent project should generate eclipse files for all subprojects. The issue with this is that it doesn't include the groupId by default and only uses the artifactId.
So:
mvn eclipse:eclipse -Declipse.projectNameTemplate=[groupId].[artifactId]
This includes the group id in the project name, which is what the default behaviour should have been to begin with. Now the projects are named correctly in the .project files (my.group.moduleA, my.group.moduleB), but the .classpath files are all screwed up because they are still only using the artifactId and trying to reference projects moduleA and moduleB.
Am I missing something here or is this a bug in the maven eclipse plugin? It seems like a name change should propagate to everywhere the name is used. I.e. It should reference the project dependencies correctly and not require a bunch of manual classpath fixes inside eclipse that will get overwritten the next time mvn eclipse:eclipse is run.
The <name> element of the .project file gets set correctly, but it's using the wrong names in both the .classpath file and <projects> section of the .project file.
MVN Version: 3.2.5
The maven-eclipse-plugin is nowadays considered as abandonned. You better have to simply import your raw projects direcly from Eclipse (with m2eclipse installed) as Maven projects. Then the setup should be done properly.

maven dependencies to a parent project build path in eclipse

I am using m2e. So I have two projects. When I right click on them both have maven enabled. So one of the projects is a parent project so it has many sub packages each sub package is correctly src\target, but not the parent itself. I have pom.xml for parent and all the children.
When I right click on these two projects then maven then update configuration. The maven repository gets added to the simple project but not to the one which is a parent of the rest. So what should I do in this case?
You have to perform a mvn install for the artifacts to get installed in the repository, the "update project configuration" is similar to the mvn eclipse:eclipse goal of the maven eclipse plugin.

What's a good Maven project structure when developing in Eclipse?

I am new with the Maven. I have two projects. I want this kind of tree:
project1
--pom.xml
project2
--pom.xml
pom.xml
which means I performed aggregation and inheritance. By doing like this and importing two projects in eclipse, the second project can't see junit dependency which is specified in the outer - common pom.xml.
The problem with the first project is that instead of having packages i see only folders.
Try using Package Explorer in Eclipse in order to see packages instead folders.
Also for this kind of inheritance try to add both projects in one parent project and import this one into Eclipse. In both .pom files of projects you must specify their parent project
As MykoB has said, ensure the common pom.xml has project1 and project2 defined as modules. In each of the child project, specify the common pom.xml as parent.
Choose the folder containing the parent pom.xml when importing the project in Eclipse and you should have the parent and both the child modules imported correctly.
This assumes you have the latest Eclipse Indigo with m2e plugin.
What you've built is the correct default Maven module structure, but Eclipse likes to have all its projects at the same level. That is, your root pom.xml which contains the module entries should be in a folder of its own, like so:
WorkspaceFolder
\_project1
\_pom.xml
\_project2
\_pom.xml
\_Builder
\_pom.xml
\_Parent
\_pom.xml
The Builder pom.xml has module entries that look like <module>../project1</module>. That's your aggregation part. Additionally, if you want to have a parent pom for inheritance (which is not necessarily related to having a pom with modules), you'll have to add the Parent entry to project1, project2 and Builder's pom.xml, and you'll need to have a <relativePath>../Parent</relativePath>.
Note that all relative paths come from the problem that you're adapting your subfolder structure to what eclipse likes.

m2eclipse multiple module projects

I have one parent parent maven project that defines dependencies.
Then I have my parent project, which inherits from parent parent project. My parent project has multiple modules each of which has a pom file.
From command line I can just build my parent project and it all works, all my modules compile and build, and even tests pass.
But when I create new java project from root of my parent project in eclipse, it never creates Maven Dependencies, and I don't see the jars from the parent parent project. I end up not being able to see any of the jars that my projects use.
I've tried updating project dependencies, I've tried updating project configuration, and numerous other cleans, builds etc, but nothing has worked.
Any idea how I might get this to work?
Thanks
--MB
In order to work in eclipse, each module needs to be its own project. You will have to add each module to your workspace individually. M2Eclipse should still recognize the parent POMs as long as they are either in your local repository, or at the path specified by the relativePath attribute of the parent group.
If you want to include all of the parent project POMs in your workspace (so you can use the POM editor on them), you can add them as projects, then remove all of the source folders from the Project Build Configuration.