Is there any benefit in using Maven Multimodule when working in a small application?
Asked Answered
I

5

10

We are building a small application using different architectural layers such as domain, interface, infrastructure and application. This follows the Onion DDD model. Now I am wondering if there is any benefit in splitting the application into a multimodule maven project. As far as I can see now it seems to make things more difficult than needed. The entire application will be deployed as a single WAR file into a Tomcat container.

Innermost answered 13/7, 2011 at 8:0 Comment(3)
What exactly is more difficult than having a single module?Padnag
The difficulty to use a consist Spring applicationContext.xml through all modules. I guess that i need to create an applicationContext.xml for usage within Spring for all seperate modules, or am i missing something?Innermost
You shouldn't need multiple application contexts. You can have several separate modules, and only one applicationContext.xml to wire up dependencies from those modules.Viaduct
U
11

Splitting your application makes sense for the following:

  • When a certain part of the project needs to have new functionality or bug fixes, you can simply focus on that module and run just the tests for it. Compiling a fraction of all the code and running just the related tests speeds up your work.

  • You can re-use the code from the modules across different projects. Let's assume your project contains some well-written generic-enough code for mail sending. If you later have another project that need mail sending functionality, you can simply re-use your existing module or build upon it (in another module by adding it as a dependency).

  • Easier maintainability on the long run. Maybe now it seems like a small project. In a few months things might look different and then you'll need to do more refactoring to split things into logical units (modules).

  • Conceptual clarity (as added by Adriaan Koster).

Concerning the WAR: You can have an assembly module which puts things together and produces a final WAR file from all the related modules.

Initially, this may seem as more work, but in the long-run, modularized projects are easier to work with and to maintain. Most sane developers would prefer this approach.

Unbated answered 13/7, 2011 at 8:41 Comment(1)
Another benefit: it enforces conceptual clarity of your architecture.Wystand
N
5

Using multiple modules forces you to have a hierarchy of dependencies. You have one module which is standalone and doesn't depend on any other of your modules. You have another which only depends on that. It might appear harder than allowing anything to depend on anything else but this approach results in a mess of dependencies which is hard to fix later.

If you are trying to follow a layered model I suggest you place each layer in a different module. This will ensure you are not tempted to break the model.

Nuzzle answered 13/7, 2011 at 8:5 Comment(0)
F
3

Short answer: today it is small, tomorrow it will bigger and more complicated to maintain, reuse, extend, integrate with other system and so on

Frons answered 23/11, 2015 at 17:51 Comment(0)
E
1

As far as I know, Maven do little help for WAR dependencies. As you are talking about single WAR, this should never be a problem.

You can separate java classes into several "jar" submodules, but if you split the WAR project into several smaller WARs, using some kind of "overlapped" packaging things get complicated.

Just information, one of our projects, it contains too many web pages, so we decided to split it into several WAR submodules, however, the session is not shared between different WARs deployed, and we are not going to use Kerberos stuff. At last, we modified a lot sources of Glassfish, Jetty, MyFaces, etc. To make them resolve web.xml stuff inside JARs. And converted the whole project to Facelets 2.0 (to avoid the dependency of JDK tools.jar and custom resource handler), the only reason is to change the WAR submodules to JAR submodules, and move all webapp/pages into class resources. So the conclusion, Maven does great job for JAR dependencies, but no WAR or single WAR.

EDIT You can put applicationContext.xml in one of the base submodule, and import it by classpath:com/example/applicationContext.xml. Also Spring 3.0 do have annotation supports, you can make spring auto scan them instead of declaring them all in the xml.

Ernestoernestus answered 13/7, 2011 at 13:46 Comment(0)
L
0

Spliting your project into multiple maven projects is useful if you want to reuse your classes in another project or if your projects are deployed in different configurations.

Maybe think of a webservice - if you are hosting the server, you could build a project for your domain classes (models) and your endpoint interfaces that could be used by server and client. The server would be another project that is build to a WAR.

To develop further clients the first project could be used, too.

Use a parent project for dependency management on common projects (like logging) and different profiles and build configurations.

Lug answered 13/7, 2011 at 8:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.