I need to have the easiest way to ensure the implementation of the interface through an external bank. I want to avoid using text / xml files, as this can cause errors when refactoring class or interface names.
I tried Netbeans Lookup, since it @ ServiceProvider annotations should register the implementation in a declarative way.
So, I wrote a simple trial code that does not even break the interface and the provider in different banks, but it still can not find the components:
import org.openide.util.Lookup; import org.openide.util.lookup.ServiceProvider; public class LookupTrial { public static void main(String[] args) { IService s = Lookup.getDefault().lookup(IService.class); if(s==null) throw new RuntimeException("lookup failed"); else s.hello(); } public interface IService{ public void hello(); } @ServiceProvider(service=IService.class) public class MyImplementation implements IService{ public MyImplementation(){} @Override public void hello() { System.out.println("hello lookup"); } } }
Am I using Lookup incorrectly? Do I have to look for another Lookup library to do what I need?
source share