Detailed explanation of building java9 service instance using maven
order
This paper mainly studies how to build java9 multi module and service instances in Maven
maven
The whole project is the same as the traditional Maven multi module project structure. A module of java9 corresponds to a module of Maven project. The following is the POM file in the root directory:
A maven compiler plugin is managed here, and the release is configured as 9. Because java9 supports multi release and can support multiple Java versions at the same time, it is compiled as java9 version here.
service-sort
This is the service interface module
Here, we also declare uses sortservice, which means that it needs to use serviceloader in this module to load the service instance
While declaring the interface, static methods are also added to load service instances.
service-sort-bubble
maven
The dependency on the API package is added here
module-info. java
This declares that BubbleSort provides the implementation of sortservice
BubbleSort
service-sort-merge
maven
module-info. java
This declares that mergesort is the implementation of sortservice interface
MergeSort
consumer
maven
Note that there are no implementation class dependencies added here
module-info. java
Main
Compilation and operation
compile
This is executed under the root directory
Using the bubble