How JarsLink Enables Dynamic Modular Development in Java Applications
JarsLink is an Alibaba open‑source Java modular framework that allows runtime dynamic loading, unloading, and inter‑module communication of JAR packages, offering plug‑and‑play isolation, versioning, and resource management to simplify large‑scale backend development, reduce deployment time, and support use cases such as data integration, micro‑service testing, and backend systems.
JarsLink Overview
JarsLink is a Java‑based modular development framework, an open‑source project from Alibaba, widely used in Ant Financial's micro‑loan business groups.
Requirement Background
Application splitting leads to high maintenance cost or difficulty removing unused features.
Faults are not isolated; changes in one feature may affect others.
Multiple branch development causes merge conflicts.
A single core change or base JAR upgrade forces a full system regression.
Upgrade and migration costs are high for middleware.
Benefits of Modular Development
Plug‑and‑play: applications consist of modules that can be added, removed, or migrated across systems.
Fault isolation between modules.
One module per branch eliminates code conflicts.
Changes affect only the targeted module.
Dynamic deployment enables runtime module addition, speeding up bug fixes and releases.
Multi‑version deployment supports A/B testing.
Reduced resource consumption by decreasing the number of applications and machines.
Application Scenarios
Data Management Center – each data source is a separate module, allowing rapid addition or bug fixing.
Backend Management Systems – isolate business‑line modules to avoid code conflicts and improve stability.
Microservice Integration Testing – combine multiple FAT JARs into a single process for debugging.
Metric Calculation Systems – route messages to different modules for processing and output.
Several Ant Financial micro‑loan systems already use dozens of modules built with JarsLink.
JarsLink Features
Isolation
Class isolation: each module uses its own ClassLoader, allowing different versions of the same library.
Instance isolation: each module gets an independent Spring context; failures in one module do not affect others.
Resource isolation (planned): future support for per‑module CPU and memory limits.
Dynamic Capability
Dynamic publishing: modules can be loaded at runtime without restarting the system, bypassing the parent‑delegation model.
Dynamic unloading: modules can be cleanly removed at runtime.
Ease of Use
Provides flexible APIs for interaction between the system and modules.
Implementation Principles
Module Loading
JarsLink creates a new URLClassLoader for each module and supports overriding the parent‑delegation mechanism for specified packages.
Module Unloading
Unloading requires that no instances, classes, or class loaders of the module are still referenced. The unload sequence is:
Close resources such as HTTP connection pools or thread pools.
Close the Spring IOC container via applicationContext.close().
Remove references to the module’s class loader.
Unload the JVM tenant (future feature).
Inter‑Module Isolation
Three levels of isolation are provided:
Class isolation via separate ClassLoaders.
Instance isolation via separate Spring contexts.
Resource isolation (planned with ALIJVM multi‑tenant).
Class Loading Mechanism
Unlike OSGi’s package‑based model, JarsLink uses a flat hierarchy where each module shares a common parent ClassLoader (e.g., KernelAceClassLoader in SOFA applications).
Framework Class Diagram
The main classes are:
AbstractModuleRefreshScheduler : entry point that periodically scans for module changes.
ModuleLoader : engine responsible for loading modules.
ModuleManager : registers, unloads, finds modules and executes actions.
Module : represents a module containing multiple actions.
Action : executable unit inside a module.
How to Use JarsLink
1. Add Maven Dependency
Include the JarsLink Maven repository and its required dependencies in your pom.xml.
2. Register JarsLink Beans
Add the two required beans to the Spring context.
3. Integrate JarsLink API
Extend AbstractModuleRefreshScheduler and provide module configuration. The scheduler refreshes modules every minute and reloads them when the version changes.
Configuration fields include:
name : globally unique identifier.
enabled : whether the module is active.
version : version string that triggers reload on change.
Properties : Spring property file.
moduleUrl : local path to the JAR.
overridePackages : packages that bypass parent delegation.
4. Develop a Module
Implement one or more Action classes inside the module.
5. Invoke Module APIs
Use ModuleManager to locate a module by name, then find and execute the desired Action.
Other Features
Spring Configuration
Module properties can set Spring bean values via the Properties field.
Best Practices
HTTP Request Forwarding
Forward HTTP requests to a module for processing.
<img src="https://mmbiz.qpic.cn/mmbiz_png/LwZPmXjm4WxZQt1HXgYPwKpTPyC2s5S7H1uicvAFDM36ONUllCniaI82RvKeb9s6z6LKx60t8mvX0hUbFxte1euw/640" />Message Request Forwarding
Route messages to modules using topics as module names and event codes as action names.
Key Interfaces
ModuleManager
Responsible for registering, unloading, locating modules and executing actions.
ModuleLoader
Handles the actual loading of modules.
Future releases will add multi‑version loading, inter‑module calls, and full resource isolation.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Developer
Alibaba's official tech channel, featuring all of its technology innovations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
