Creating a multi-module project from Maven into one war file

My question has been asked before, which I know, but I think I am trying to do something a little different if the existing answers don't fit.

Basically, I want to have multiple projects in Eclipse to be built (preferably) into one final WAR file. Perfectly:

root - pom.xml
|___ java-app
|___ web-service-v1
|___ web-service-v2
|___ web-service-v3
|___ rest-service
|___ batch-service


Imagine a Java application is a real application, and each additional component acts as a decoupled presentation layer for the Java application itself. Ultimately, the Java application will run on a tomcat instance, with different modules providing their services. I would like all the different modules to run in the same Spring container as well.

I don't know that running in Maven modules is the best way to do this, but I'd rather have each component in a separate Eclipse project that will eventually be built together.

Can anyone provide any suggestions as to how I would use Maven to build this?


source to share

3 answers

Just create a separate military module:

root - pom.xml (packaging: pom!!!)
|___ java-app
|___ web-service-v1
+--- mod-war (pom.xml)


and install the dependencies of the modules you would like to add to the war file in the pom, and that's it.



The basic idea behind Maven is that each module should generate one build artifact (like a jar or war file). The parent pom is usually responsible for global configuration and dependency management, as well as correct modular orchestration. If your end result should be a WAR file, the last module on the list will be a web application. Other modules can provide classes that the war file depends on.

There are more complex build structures out there, but the above one should be enough for you.



This is somewhat dated, but hope this additional information helps someone.

@Mousc Miscellaneous An example of saving Spring configurations in each module and referencing them from web.xml can be found here in the Sonatype book . I think this is what you are looking for.

PS: Sorry, I had to add this as a new answer. I probably don't have enough points to answer the other answers.



All Articles