user691197
user691197

Reputation: 1009

multi module maven project structure in eclipse

I have two modules under a main project

main
|
|
--module-a
|
|
--module-b

I created it using eclipse->new ->Maven project, eclipse->new->maven module.

The structure in the file system looks correct. But in eclipse, it shows module-a, module-b as two new projects in the package explorer.

My main project looks like this.

enter image description here

I have seen few multi module projects where, the modules are present within the main project in package explorer. The main project had

module-a/src/main/java
module-a/src/test/java
module-a/src/resources/java
module-b/src/main/java
module-b/src/test/java
module-b/src/resources/java.

How do I convert my project to look like this ?

Upvotes: 2

Views: 11486

Answers (6)

ankel
ankel

Reputation: 145

I solved this problem as follows:

Under the "Project Explorer" click on the "View Menu" (little triangle) and select "Filters and Customization..."

enter image description here

Under the "Content" tab tick "Nested Projects"

enter image description here

Finally, Under the "Pre-set filters" tab tick "Nested Projects: hide folders when projects is shown as nested" and "Nested Projects: hide-top-level project if shown as nested".

enter image description here

By doing that I come up with the following structure.

enter image description here

I used a Spring Tool Suite 3: Version: 3.9.11

Upvotes: 1

Shashi
Shashi

Reputation: 41

You can do this in earlier versions of eclipse as well. Close and Remove the sub-module projects (as they are already present in the parent folder). Now click on Properties on the main project -> Project Facets -> Convert to faceted form. This will detect Java automatically, Click on Apply, OK. Now you can see that these modules are created with Source folders

Upvotes: 0

Mickael
Mickael

Reputation: 3596

Starting from Eclipse 4.5.M5 (that you can already download at http://eclipse.org/downloads ), the Project Explorer view has a parameter to show projects hierarchically, to better handle such case. See https://www.eclipse.org/eclipse/news/4.5/M5/ for details.

Upvotes: 11

DaveM
DaveM

Reputation: 734

You will find if you navigate the actual file system (oe use the 'navigator' view in eclipse) that the sub modules do in fact exist underneath the main parent project folder.

Eclipse is nice enough (clever enough or whatever) to pull them out when you use the 'package explorer' view. I guess this makes it easier to find and navigate your way aournd a highly modular project.

However if you set up your Parent POM correctly you can have a flat structure to your modular project if you so desire (I haven't as yet been able to get this to work, so far I think it is related to the sub module classpaths or something?).

David.

Upvotes: 1

Andrew
Andrew

Reputation: 490

I have seen few multi module projects where, the modules are present within the main project in package explorer.

Thats what do maven eclipse plugin. It just create single project with multiple source directories for each module of maven multimodule project.

If you want to see some hierarchical structure in eclipse - use working sets. Create working set with name of parent, add module-a and module-b to it and visually it will be separated from other projects in eclipse workspace.

Upvotes: 0

Zoltán Ujhelyi
Zoltán Ujhelyi

Reputation: 13858

Basically, Eclipse does not support the Maven way of structuring projects.

By using the M2E it is possible to execute Maven as part of the build, but that way you lose the project management and incremental build capabilities of Eclipse.

You can also simply use the Eclipse layout in the IDE, and build with Maven in the build server, but that way you have to make sure the two build are identical.

Upvotes: 0

Related Questions