Using lookup outside NetBeans Platform means that the getDefault() lookup contains only the meta-inf services and the classloader. Which isn't bad if you do your jars with services. But in my case I don't.
So I needed somehow a way to add some objects in the global lookup. Nothing easyer: just define the System.property: org.opeinde.util with your classname (which must be a Lookup.Provider) and them make your own public methods to add objects to the lookup.
So I had com.example.MyLookup registered, with my own static method addToGlobal() and that was I. I could register with the lookup things like the main frame, etc. and use it with the normal Lookup.getDefault.lookup(MyObject.class). Fun stuff !
If this was helpful for you then maybe you'll like reading the other NetBeans Platform-related posts.
--
Emilian Bold
Java-loving consulting services from Timisoara, Romania.
3 comments:
can you post a code sample of your class?
Thanks!
Can you please describe how to do this:
Nothing easyer: just define the System.property: org.opeinde.util with your classname (which must be a Lookup.Provider)
I tried searching in mailing list archives but couldn't find anything pointing to this
with regards
Tushar Joshi, Nagpur
Not sure where this is documented, but if you look at the Lookup.getDefault() implementation you should see this line:
String className = System.getProperty("org.openide.util.Lookup");
and then
defaultLookup = (Lookup) Class.forName(className, true, l).newInstance();
Basically you could just have the following rough code:
System.setProperty("org.openide.util.Lookup", MyLookup.class.getName());
and afterwards Lookup.getDefault() should be an instance of your MyLookup class.
Post a Comment