pk.avj
pk.avj

Reputation: 131

Can java.util.ServiceLoader find the new jars added to the classpath without restart?

I have a java application which is implemented to find providers of an interface using java.util.serviceLoader. When I a add a new provider jar at runtime to the classpath of the application the application is not finding it. If I restart the application the application finds the provider jar. Are there any options for java application to find the provider jar at runtime as I think that is what java serviceLoader is supposed to do.

I am following the instructions in this page. http://cr.openjdk.java.net/~mr/jigsaw/spec/api/java/util/ServiceLoader.html Deploying service providers on the class path

Upvotes: 2

Views: 875

Answers (1)

Angry Coder
Angry Coder

Reputation: 167

Explanation can be found here Creating Extensible Applications (at the end of the tutorial):

Limitations of the ServiceLoader API The ServiceLoader API is useful, but it has limitations. For example, it is impossible to derive a class from the ServiceLoader class, so you cannot modify its behavior. You can use custom ClassLoader subclasses to change how classes are found, but ServiceLoader itself cannot be extended. Also, the current ServiceLoader class cannot tell your application when new providers are available at runtime. Additionally, you cannot add change-listeners to the loader to find out whether a new provider was placed into an application-specific extension directory.

Seems to apply to Java 8. Don't know if this has changed in the later editions.

Upvotes: 1

Related Questions