ServiceMonitor

Overview

The ServiceMonitor application serves as an illustrative example of how a modularized project is structured. It is designed to demonstrate the steps involved in declaring, compiling, and running modules within a Java application. By using ServiceMonitor, developers can gain insights into the anatomy of a modularized project, which is structured to mimic a larger, more complex system, thereby showcasing the practical use of the Java module system.

Modularizing the ServiceMonitor Application

The process of modularizing the ServiceMonitor application involves several key steps:

  1. Cutting the Application into Modules: The application is divided into distinct modules, each encapsulating a specific functionality or service. This modularization helps in managing dependencies and enhances the maintainability of the codebase.

  2. Source Code Layout: The source code is organized on the filesystem in a manner that reflects the modular structure. This organization is crucial for the Java module system to correctly identify and compile the modules.

  3. Declaring, Compiling, and Running Modules: Each module is declared with a module descriptor, compiled, and then prepared for execution. The compilation process ensures that all modules are correctly built and placed in the designated 'mods' folder.

Running the ServiceMonitor Application

To execute the ServiceMonitor application, it is essential to ensure that all modules are compiled and available in the 'mods' folder. The application is launched using the following command:

$ java
 --module-path mods:libs    #1  
 --module monitor    #2
  • #1: Specifies the folders where Java searches for modules. This includes both the 'mods' folder containing the compiled modules and any additional libraries in the 'libs' folder.
  • #2: Indicates the name of the module to launch, which in this case is 'monitor'.

This command allows the Java module system to resolve dependencies and manage any potential conflicts, ensuring a smooth execution of the application.

Example Structure

The ServiceMonitor application is composed of seven modules, each serving a specific purpose within the application. Additionally, it relies on external dependencies such as Spark and Hibernate. When launched, these modules form a universe of observable modules, with 'monitor' acting as the initial module. This setup exemplifies how a modularized application can be structured to efficiently manage both internal and external dependencies.