I am very new to java and android development and to learn I am trying to start with an application to gather statistics and information like munin does. I am trying to be a
I've figured out a solution that may work for some situations. Instead of ServiceLoader
, I'm using the org.openide.util.Lookup
class / library that comes with NetBeans - it is a superset of ServiceLoader
. It does not require NetBeans itself and seems to work ok with Eclipse. It is necessary to replace whatever ServiceLoader
functionality you are using in your application with Lookup equivalents, and add the org-openide-util-lookup library. Then, you can just do something like this:
Lookup lookup = new ProxyLookup(Lookup.getDefault(),
Lookups.metaInfServices(myClass.getClassLoader(), "services/"));
And move your ServiceLoader
files from META-INF/services/ to services/.
Note that, because of the ProxyLookup
, this will continue to work on standard Java environments unchanged (i.e., in those cases it will continue to look in META-INF/services).
Here is a link to the documentation for the library: http://bits.netbeans.org/dev/javadoc/org-openide-util-lookup/org/openide/util/lookup/Lookups.html
UPDATE
After working with this for a couple of days, it seems to function well - I move between environments (standard Java and Android) and it works properly in each location. The primary downside is having to manually copy the files to the /services directory.