Single-module vs Multi-modules maven project - maven

I'm creating a new java web project. This web application will have many modules such as core/commons, business service, repository, security, integration, ldap, user management,.... I wonder if I should separate each module into each maven project (jar file) or create project that include all java packages of all modules into single one maven project.
Structure of Multi modules maven project
mycompany-core
mycompany-repository
mycompany-api
mycompany-usermanagement
mycompany-business
mycompany-web
Structure of Single module project:
mycompany-web
|___ src
|____ main
|____ java
|____ com.mycompany.core
|____ com.mycompany.repository
|____ com.mycompany.business
|____ com.mycompany.controller
When should we apply multi-modules or single-module project> Please give me some advice.

All products I've worked on in Maven were multi-module. This is because they tended to be big. However, when I create my own pet projects, they are normally single-module ones.
As a rule, as products grow, they will need to be organized into multi-modules. Some projects start as a single module and are split as they grow. Others, created by developers with more experience, are already divided up, because the developers already know how the code will grow and how it needs to be organized.
Specifically, from your list, "core/commons, business service, repository, security, integration, ldap, user management", I would separate "commons" into its own module, because it smells like it could be reused on other projects. The other parts could all fit into one module, but I'd need more insight into the project.

It is depend on your requirement. If you want to run this using .sh or .bat you should have single target(single jar with other libraries).
If your project build as an API it is better to have your build as multi module one.

Related

How to create a new microservice spring?

I'm using Intellij IDE Ultimate and I create a Project with spring inicializer. The problem is... now I need create more microservices (Spring Boot) but idk how to do this in IDE. I the end I need 3 microservices. Have a terminal command to create a new microservice inside my project? Or a way in the IDE to do this.
What you need to do is creating several modules (normally Maven modules), each of them is a SpringBoot application with its own application context and its own configuration, directories structure, etc.
IntelliJ has a concept of Module which matches very well the Maven module concept.
If you go to File, Project Structure, Project Settings, Modules you can see a very nice view of the current modules (in your case it should be only one). You can add or remove modules there. (Also by just clicking File-New Module, but the Project Structure View is more useful).
If you decide going the Maven way, you can also create your structure in disk and its POMs and import maven project in IntelliJ.
In any case, keep in mind that you will like to deploy every microservice as a separate and autonomous deployable unit.

Liferay7 service builder dependency

I have created a service builder project (Gradle type) in Liferay7 called register-user. There is another service builder project called register-organization. I have a situation where one of the service builders depends upon other. However, i am not able to figure out where to put the dependency of one into another. Is there is any way to do that?
With each servicebuilder project you create from the template, you get two projects, e.g. register-user-api and register-user-service. The -service project depends on the -api project and has the dependency noted in its build.gradle. Look it up and use exactly the same notation to make any other project depend on register-user-api.
The situation changes if both projects do not live in the same workspace: In that case you'll need your own repository (e.g. proxy for Maven Central) where you publish your own modules. Then you can just declare a standard dependency for your modules.

When to use maven multi module project

I was going to couple of blogs to get the basics of maven, in the mean time I was confused when I can use the multi module project. It will be great if the answer includes example.
The main idea is that you have small modules that are dependent on each other and can be grouped together. Its not necessary that all sub-modules in a multi-module project be dependent on every other sub-module.
Lets consider you have multiple modules for an application (e.g a social networking application) that belong together. These modules can range from smaller modules like a client consumer module or a server module that will serve requests initiated by the client module, an ejb module that will hold your beans that are used by both the server and the client module and a deploy-able web module that would comprise of your front-end application etc.
This is usually handled via a multi-module build which means all modules have the same version number, are bound together under a similar platform (a social networking application in our example) but can be accessed and used by other separately.
Please check How to assemble multimodule maven project into one WAR? to know how to package a multi module project in a war file. also, you can check maven official site on Introduction to pom file

multi-module spring roo project setup

I am really new to Spring Roo (perhaps been using it for 2.5 months) and on the whole it has been a very good experience, and I have rapidly created a system for managing a property portfolio.
HOWEVER, this system was developed in three seperate roo projects:
Property Management - mongo backend
Accounts Management - mongo backend
Address Book - JPA
Now I am looking to combine them in one project, with one home page to access all three parts, I am aware of maven multi-module support which Is included in roo, but when I attempted to combine the three projects by creating a Spring Roo Multi Module Project, defining the three modules and then importing each of the three modules into their respective folders, on deployment only the first module to be reached in the compilation was setup and the path for localhost access was not the name of the multi-module project but the name of the project which was compiled..
Does anyone know any resources or have any tips for creating a multi module webapp from the combination of three existing webapps?
Thanks
Just start with a folder structure like this:
root (pom.xml) Aggregator
+-- mod-mongo-property
+-- mod-mongo-accounts
+-- mod-jpa
Move all comming things like dependencies and plugins (in particular versions) into appropriate parent (depenendencyManager, pluginManagement).

Building multi-module project from Maven into one war file

My question has been asked before, which I know, but I think that I am trying to do something slightly different, where existing answers are not appropriate.
Essentially, I do want to have multiple projects in Eclipse that will be built (preferably) into one final WAR file. Ideally like this:
root - pom.xml
|___ java-app
|___ web-service-v1
|___ web-service-v2
|___ web-service-v3
|___ rest-service
|___ batch-service
Imagine the Java App as the actual application, and each additional component runs as a decoupled view layer for the Java App itself. Ultimately, the Java application will be running in a tomcat instance, with the different modules providing their services. I would like all the different modules also to run in the same Spring container.
I don't know that running in Maven modules is the best way of doing this, but I would really prefer to have each component in a separate Eclipse project that ultimately get built together.
Can anyone provide any suggestions as to how I would use Maven to build this?
Just make a separate war module:
root - pom.xml (packaging: pom!!!)
|___ java-app
|___ web-service-v1
..
+--- mod-war (pom.xml)
and put the dependencies of the modules you would like to have added to the war file into the pom and that's it.
The main Maven idea is that each module must produce a single build artifact (e.g. a jar or a war file). The parent pom is usually responsible for global configuration and dependency management and also for a proper module orchestration. If your final result need to be a WAR file, then last module in the list will be the web application. The other modules could supply classes that war file depend on.
There are more complicated build structures, but above one should be sufficient for you.
This is somewhat dated, but hope this additional info helps someone.
#Mouscellaneous An example of keeping Spring configs in each module and referencing them from the web.xml can be found here in the Sonatype book. I guess this is what you are looking for.

Resources