On Thu, Oct 9, 2014 at 12:53 PM, Harald Albers <[email protected]> wrote:
> a single jar containing
>
> service interface,
> service implementation,
> provider-configuration file in META-INF/services
> code that triggers service discovery

First of all, that code is dubious. If you have an _expected_
implementation that is collocated in the same JAR, it should simply
instantiate it directly (via constructor). If it wants to use
ServiceLoader for extensibility, great, but it should use it for
_other_ implementations only.

> Same thing happens when I call
> ServiceLoader.load(DockerCmdExecFactory.class) form the plugin code.

ClassLoader orig = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(Jenkins.getInstance().getPluginManager().uberClassLoader);
try {
    ServiceLoader.load(DockerCmdExecFactory.class);
} finally {
    Thread.currentThread().setContextClassLoader(orig);
}

ought to work. As should

ServiceLoader.load(DockerCmdExecFactory.class,
Jenkins.getInstance().getPluginManager().uberClassLoader);

if you are writing the code calling SL.load, or the code that does so
allows a ClassLoader to be specified as an argument.

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to