ServiceLoader

suggest change

Versions

ServiceLoader has been part of Java SE since 6.

Remarks

ServiceLoader can be used to get instances of classes extending a given type (the service) that are specified in a file packed in a .jar file. The service that is extended or implemented is often an interface, but this is not required.

The extending/implementing classes need to provide a zero argument constructor for the ServiceLoader to instantiate them.

To be discovered by the ServiceLoader a text file with the name of the fully qualified type name of the implemented service needs to be stored inside the META-INF/services directory in the jar file. This file contains one fully qualified name of a class implementing the service per line.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents