Peter
Peter

Reputation: 101

Maven: Can I have parent and child modules in same Eclipse project?

I need to create a Spring MVC web application where each of the services should be created as a separate JAR file. Some of the docs suggest that multiple Maven modules can be used for this. But what I understood is, that each module also needs to be created as a separate Eclipse project.

Can I have all the controllers, service and DAOs in the same Eclipse project, while still creating separate jars for each service (and a war file for the whole application) with Maven?

Upvotes: 1

Views: 1110

Answers (2)

Karl
Karl

Reputation: 906

Short answer:

Yes, you could create multiple build targets (jar files) out of single project by using maven-jar-plugin (profiles, executions).

https://maven.apache.org/plugins/maven-jar-plugin/


Should you do it?

I believe most people will agree with me that you should not do it, you should stick to one of the most important core concepts of Maven: modularity.

Now, Have you asked yourself the question, Do I really need to create multiple modules (jar Files) for my application? Can I manage all pieces of code in one single project?

Maybe you just need some guidance about how to organize your java packages in one single project.

https://dzone.com/articles/layered-architecture-is-good - Using layered architecture

http://www.javapractices.com/topic/TopicAction.do?Id=205 - Packages by feature vs Layers

NOTE: If you think that your project will grow fast and the number of classes will be a large number, it is probably a good candidate to be a multi module application.


If you still have the feeling that you have to create multiple modules, there are several interesting posts about how to address modularity in the design of applications, in these posts they provide very interesting reasons/criteria why you should split your application into modules.

How to decompose a system into modules?

Spring Java Maven Project + Module Design

Good Luck!

Upvotes: 2

oberlies
oberlies

Reputation: 11723

What is the problem of separate modules and hence separate Eclipse projects? If you declare a Maven dependency between the modules, you'll be able to have compile dependencies between the classes in the corresponding Eclipse projects.

So I suppose that it is possible to force multiple Maven modules into one Eclipse project, but I don't know any good reason to do so.

Upvotes: 0

Related Questions