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.
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