Created
October 26, 2011 11:21
-
-
Save chbaranowski/1316073 to your computer and use it in GitHub Desktop.
OSGi Bundle Context - Get Bundle Context from the ClassLoader via BundleReference Version via OSGi FrameworkUtil class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.osgi.framework.BundleContext; | |
import org.osgi.framework.FrameworkUtil; | |
import org.osgi.framework.ServiceReference; | |
import org.osgi.service.packageadmin.PackageAdmin; | |
public class MyDemoClass | |
{ | |
public PackageAdmin getService() | |
{ | |
// get bundle instance via the OSGi Framework Util class | |
BundleContext ctx = FrameworkUtil.getBundle(MyDemoClass.class).getBundleContext(); | |
ServiceReference serviceReference = ctx.getServiceReference(PackageAdmin.class.getName()); | |
return PackageAdmin.class.cast(ctx.getService(serviceReference)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using hudson build , it throwns an error Compiler Error: cannot find symbol symbol : method getBundleContext() location: interface org.osgi.framework.Bundle. Please let me know how to fix it . I am usign the below in pom
org.osgi.core org.osgi.core 4.3.0 jar compile org.apache.felix org.apache.felix.framework 5.0.1 runtime