I am looking to set up a multi module maven project (described below) that would scale well. I have some questions about the approach which is largely drawn from the Sonatype example.
I have done a certain amount of reading on maven multi module projects but couldn't find an example going beyond the basic level.
Good project structure for a modular Spring, JSF2, Maven based project, that would allow for builds involving a selection of modules and their dependencies.
It should be possible to deploy an individual web module on a lightweight container like Tomcat/Jetty through Maven configuration (like jetty-maven-plugin). This should be able to pull in the necessary dependencies through Maven. That makes it easy during development to focus on the module being worked on (not having to run a full build and deployment) and deploy the full application only in a complete build.
The setup should allow for multiple distributions based on a selection of modules to be included in the build. I take it this can be achieved through the use of build modules that will pull and package the corresponding modules.
Core domain classes.
somapp.core (maven project)
|- someapp.core (maven module)
|- someapp.core.tests
Account Management Domain classes
someapp.accountmgmt
|- someapp.accountmgmt
|- someapp.accountmgmt.tests
component1 domain classes
someapp.component1
|- someapp.component1
|- someapp.component1.tests
Service 1 - # account management (User login)
someapp.accountmgmt
|- someapp.accountmgmt.api
|- someapp.accountmgmt.impl
|- someapp.accountmgmt.mocks
|- someapp.accountmgmt.tests
someapp.service2
|- someapp.service2.api
|- someapp.service2.impl
|- someapp.service2.mocks
|- someapp.service2.tests
|- someapp.service2.cli # CLI access for service2
someapp.service3
|- like above
someapp.accountmgmt.web
|- someapp.accountmgmt.web
someapp.service2.web
|- someapp.service2.web
someapp.service3.web
|- someapp.service3.web
someapp.build1 # bundle accountmgmt and service2 into 1 war file
someapp.build2 # bundle accountmgmt and service3 into 1 war file
somapp.build3 # bundle accountmgmt, service2 and service3 into 1 war file
(i.e. someapp.accountmgmt.web.war, someapp.accountmgmt.jar, someapp.service2.web.war, someapp.service2.jar, someapp.service3.web.war, someapp.service3.jar, someapp.core.jar)
I understand project structures are not set in stone. I would like to set up one that is a good starting point. Suggestions / Links to examples are welcome.
A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.
To skip the basics, do the following: Download and unzip the source repository for this guide, or clone it using Git: git clone https://github.com/spring-guides/gs-multi-module.git. cd into gs-multi-module/initial. Jump ahead to Create the Library Project.
Well for the Spring part it's already discussed and an answer accepted at Spring Configuration in a multi-module project. As far as the general layout I've only seen one WAR per project and services only bundled together if they are related (e.g. UserLoginService would not go together with DomainObjectsService).
I would suggest breaking up the structure into several different projects, with the dependencies (business objects, etc) deployed as JAR projects to a local repo and listed as normal Maven dependencies in the (now different) projects that need them. Then in your app-server you can deploy the apps to different paths (e.g. yourdomain.com/app1, yourdomain.com/service2).
My compliments to your ambition though!
EDIT: There is a way to have multiple WARs if you wish, see this SpringSource blog post about Using a shared parent application context in a multi-war Spring application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With