Writing Modular Java Applications
I have a project with the following structure:
+---main | \pom.xml +---module1 | \pom.xml +---module2 | \pom.xml +---module3 | \pom.xml +---module4 | \pom.xml +---pom.xml
Modules use a mechanism
to register their services. The main class is in the module
, which is also responsible for loading services in the pathpath using the mechanism
. The problem is that the module
is not aware of
, because they are set by the user. I want to add all the classes in these modules to the classpath when the program starts up so that the ServiceLoader knows about the services in these modules.
I am currently loading these modules at runtime from a module
, but it doesn't seem to be a very good way to solve this problem because the IDE is unaware of these modules and it seems like it takes a lot longer to load these modules at runtime ... I've looked at how modular Java projects like Elasticsearch and PrestoDB deal with this problem, but it looks like they both load installed modules at runtime.
How do you deal with this problem when developing modular Java applications? Let's say I have a directory called plugins that has jar files from modules installed by the user, is there a way to run the application using the classpath that contains all the jars in that directory using the maven plugin? Or do I need to load these jars at runtime?
source to share