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.
Related
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?
I have recently had need to checkout an apache project to do some fact-finding/debugging (specifically maven-surefire-plugin, see this question). This, like most other apache projects, is a maven multi-module project. So, in eclipse, I open up the SVN Repositories browswer, add a new repository, find the project and right-click->Checkout.... In the wizard, I click Checkout as a project in the workspace and type in the name of the project.
I have the project, now I need to let eclipse know its a maven project, so right-click->Configure->Convert to Maven Project. Now the parent project is a maven project. I can right-click->Run As->Maven Build and it works. But, all the modules are just folders. Eclipse doesn't know anything about where the source code is or even if it has any. In a single module project it would have set the source folder, build folder and other configuration automatically. Further more, if you are creating a multi-module project from scratch, you start by creating the parent project, then, when you add modules to it, they each show up as individual projects in eclipse with the physical directory living under the parent project folder as needed by the default maven build process.
So now, knowing how its done when creating new projects I can File->New->Project..., choose General->Project, give the project a name (I match it to the module name), uncheck Use default location and set Location: to the path on to the module inside of the parent project folder. After clicking Finish, and repeating the process for each other module I have something that looks similar to what I would expect. I now need to convert every individual module to a maven module in the same fashion as the parent project. Great, they are all maven projects, right?
So then I open them up, and the source folder is not set.
Argh... Then I go to each project, twist it open, and on the src folder I right-click->Build Path->Use as Source Folder. Lather, rinse, repeat... Once done on all the projects, it really looks and feels like I started this project from scratch. Things function.
My question is, is it really this hard? Am I missing a shortcut? Wouldn't it make sense if Configure->Convert to Maven Project on the parent pom realized it was a multi-module project and did all the work for me? This is a very painful process for apache projects as they all seem to have many, many, modules... Anyone know of a better process?
You could try to pull all the code down outside of Eclipse, import the parent project as an existing Maven project (right-click -> Import... -> Existing Maven Projects), and see if it all comes in the way you expect. Then right-click -> Team -> Share Project... on the parent project.
I'd like to work on two different versions of the same multi-modules maven project under eclipse.
Unfortunately, when you import a multi-module maven project under eclipse, you can change the parent module project name yourself, to prevent conflicts, but not the child modules projects names. Child modules are imported as root projects, named after the module name. Apparently there is no way to rename them during import.
In an ideal scenario, I'd like to keep the pom as it is. Obviously I'd like to keep the same eclipse workspace...
Yes, you can. You have to change the name pattern in the m2eclipse importer. All modules will have this pattern and you have a conflict-free env.
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.
I'm a beginner at Maven and I've played with it from a command line point of view a little, so now I was trying to use it in Eclipse; I installed the m2eclipse plugin to do so.
But I'm stumped from the very beginning! Apparently I've missed a bit of terminology somewhere along the line. I can't keep track of all these new Maven terms... What is a Maven Project, and what is a Maven Module? These are my options when creating a new project in the Maven category in Eclipse.
They are basically the same thing, but with one difference.
When you create a module, you must specify a parent project.
When you specify the parent project, it adds a <modules> section to the parent projects pom.xml.
That section basically says to the parent project:
run every command I get against all of my modules first
So for example, if you run, mvn package on the top-level project, it will run mvn package against all its module projects first.
Hint:
Make sure all modules have high cohesion and related to each other, otherwise you will have a huge messy project without applying SRP (Single Responsibility Principle)
Found it! My searches were returning tons of hits for creating a "multi-module project", but once I added "-multi" to my query, the answer was on the first page.
According to Creating and Importing Projects:
m2eclipse provides the ability to create a Maven module. Creating a Maven module is almost identical to creating a Maven project as it also creates a new Maven project using a Maven archetype. However, a Maven module is a subproject of another Maven project typically known as a parent project.