This is simple example of 'modular' java application, based on JBoss Modules project. For further details, see this manual. Modular application means that the modules listed below have own class loaders.
This demo simulates the situation where java application has to use java libraries that are not aligned and they have same dependencies but of different versions. Artifacts used in this demo application does not need to be OSGi compatible or have special files in META-INF directory. That's why JBoss modules system is much easier to use than OSGi.
Application projects:
- modular-application - app module and module.xml files for other modules
- service-client - implementation of service-client module
- service-module-01-api - implementation of service-module-01-api module
- service-module-01 - implementation of service-module-01 module
- service-module-02-api - implementation of service-module-02-api module
- service-module-02 - implementation of service-module-02 module
- service-registry - implementation of service-registry module
Application modules:
- app - main application module, app is initialized here.
- common - common libraries like log4j, slf4j
- service-client - service that is using service-module-01 and service-module-02
- service-module-01-api - APIs for service-module-01
- service-module-01 - data service using guava 23.0
- service-module-02-api - APIs for service-module-01
- service-module-02 - data service using guava 16.0
- service-registry - simple replacement for DI
gradle clean buildmodules
In this case run pre-build application:
cd modular-application/build/app
./start-application-simple.sh
There is java.lang.NoSuchMethodError thrown and application fails because service-module-01 and service-module-02 are both using guava, but
different versions (23.0 and 16.0). service-module-02 uses intentionally deprecated APIs that are not available in newer version of guava.
Check the start script.
In this case run pre-build application:
cd modular-application/build/app
./start-application-modular.sh
This application uses static modularity, all modules are prepared in application directory app/modules and are
loaded and activated on application start by app module. The app module is started by name, see
start script.
There is no java.lang.NoSuchMethodError because modules are
separated by their own class loaders. Application runs using both version of guava.