META-INF/services directory convention¶
The META-INF/services directory convention is a standard service-provider loading facility used in Java^[600-developer-java-black-technology-serviceloader.md]. It allows service interfaces to be dynamically discovered and loaded at runtime by defining specific files within a directory structure.
Directory Structure and File Naming¶
To implement this convention, a directory named META-INF/services/ must be created within the JAR or classpath^[600-developer-java-black-technology-serviceloader.md]. Inside this directory, a file must be created with the exact name of the service interface's fully qualified class name^[600-developer-java-black-technology-serviceloader.md].
File Content¶
The content of the configuration file created in the META-INF/services/ directory consists of the fully qualified class names of the concrete classes that implement the service interface^[600-developer-java-black-technology-serviceloader.md].
Implementation¶
The Java Development Kit (JDK) provides a utility class, java.util.ServiceLoader, to locate and load these implementations^[600-developer-java-black-technology-serviceloader.md]. This class locates the configuration files within the META-INF/services/ directory, identifies the implementation classes listed within them, and typically uses mechanisms like Class.forName to load and instantiate them^[600-developer-java-black-technology-serviceloader.md]. This process is often initialized within static blocks of client code, such as in the java.sql.DriverManager^[600-developer-java-black-technology-serviceloader.md].
Related Concepts¶
Sources¶
^[600-developer-java-black-technology-serviceloader.md]