简体   繁体   中英

How to create a modular java project?

I have to create a java project where the structure will be like the below image:

在此处输入图像描述

That is the project will have a common folder that will contain mainly the framework. Then there will be different modules that are dependent on the common framework and will have their own framework. How do I set such dependency using maven/sbt? The project should be structured in a way so that:

  1. If needed the framework can be shipped as a jar to a totally different project
  2. Each module can be shipped separately as a jar.
  3. The entire project can be shipped as a jar

What am I looking for is how do I have different pom.xml/build.sbt in each level and link their dependencies?

Can you please suggest any solution?

The most important thing was already said by Andreas:

Your "framework" needs to a module like everything else. So your main project will have four modules:

  • framework
  • module1
  • module2
  • module3

The main POM will list those four as modules.

framework will contain the code of the framework. module1 will also contain no code, but two submodules for module1-framework and module1a . The POM of module1 will define those modules.

If you build the project you get jars for each and every of the (sub)modules.

You can use the assembly plugin or the shade plugin to bundle some of these to larger jars (even for the whole project), but this is rarely useful. Maven is good a dependency resolution, to there is no real need to bundle a lot of jars into one (with the exception of executable jars).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM