Accessing an osgi declarative service in a java project -


im trying access osgi ds in java project. found example on internet:

bundlecontext context = frameworkutil.getbundle(this.getclass()).getbundlecontext(); servicereference servicereference = context.getservicereference(myclass.class.getname()); myclass blah = (myclass) new servicetracker(context, servicereference, null).getservice(); blah.dostuff(); 

the problem here if run in java class "context" variable null. guess thats because not in osgi bundle.

i tried chaning things , works if change this:

bundlecontext context = frameworkutil.getbundle(myclass.class).getbundlecontext(); 

but honest dont understand bundle context. what , can same class reference class is?

manual states following: context - bundlecontext against tracking done. ... doesent make things clearer me.

thanks!

frameworkutil.getbundle(class) returns non-null if class pass in loaded osgi bundle classloader. means need in osgi bundle.

you need clearer you're trying do. "accessing osgi ds in java project" pretty meaningless. since seems you're starting out osgi, why not start simple working through basic tutorial, rather jumping in @ deep end?

finally notice following code snippet nonsense: myclass.class.getclass(). literal myclass.class gives class want... if call getclass on class of java.lang.class! not wanted.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

node.js - Node - Passport Auth - Authed Post Route hangs on form submission -

Does Firefox offer AppleScript support to get URL of windows? -