Is something similar to ServiceLoader in Java 1.5?


How do I discover classes at runtime in the classpath which implements a defined interface?

ServiceLoader suits well (I think, I haven't used it), but I need do it in Java 1.5.

By : Telcontar


javax.imageio.spi.ServiceRegistry is the equivalent with prior Java versions. It's available since Java 1.4.

It does not look like a general utility class, but it is. It's even a bit more powerful than ServiceLoader, as it allows some control over the order of the returned providers and direct access to the registry.



There's nothing built into Java 1.5 for this ...

is only a part of truth.

There is non-standard sun.misc.Service around.

Beware, it is not a part of standard J2SE API! It is non-standard part of Sun JDK. So you can not rely on it if you use, say, JRockit.

This is an old question but the other option is to use Package Level Annotations. See my answer for: Find Java classes implementing an interface

Package level annotations are annotations that are in classes.

JAXB uses this instead of Service Loaders. I also think its more flexible than the service loader.

By : Adam Gent

This video can help you solving your question :)
By: admin