I don't have a solution at hand but remember that the lookup will keep
a single object instance in memory for a given service entry while the
ServiceLoader will create fresh instances if it's just reading
META-INF/service files (unless the JAR keeps a reference to a single
ServiceLoader instance so the cache is reused).

So you want a "bridge" from ServiceLoader to the default lookup or
just a way to instantiate the services?

I guess the most heavy duty solution would be to bytecode engineer the
3rd party JAR so you it either calls the lookup or allows you to
inject values.

PS: I had the reverse problem: the ServiceLoader finding classes when
I didn't want it to find any (geotools JARs). This was happening
because those JARs were in the boot classpath for some reason.

--emi

On Sat, Aug 17, 2019 at 9:12 AM Damian Carey <jami...@gmail.com> wrote:
>
> Hi all,
>
> We have a "mature" (10+ year old) Netbeans Platform Swing product, which has 
> 35+ modules. This all works well.
>
> As usual, when one Netbeans module provides an Implementation we find it from 
> other Netbeans modules using the usual idiom ...
> Provider: puts entry in META-INF/services
> Consumer: MyClass myObj = Lookup.getDefault().lookup(MyClass.class);
>
> Our current issue is that we need to add an external jar that is NOT built 
> using Netbeans, so it can't use Lookup. I have placed this external jar into 
> a module wrapper, and one of our modules depends on it so we can successfully 
> start this service as appropriate. Again, everything is perfect with this 
> setup.
>
> The problem is that this external jar is looking for services from our 
> Netbeans platform product, it is seeking them using standard java 
> ServiceLoader capability, but the implementations are not found.
>
> I *think* that if we use the Netbeans System ClassLoader then it CAN locate 
> the implementations, however we don't want to use the system classloader 
> because it will cause other issues.
>
> Does anyone have any suggestions on how a wrapped jar might access Netbeans 
> META-INF/services implementations via vanilla Java ServiceLoader SPI 
> interface?
>
> Any suggestions would be hugely appreciated.
>
> Many thanks,
> -Damian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to