Попробуйте код ниже:
import org.eclipse.osgi.service.datalocation.Location;
public <T> T getService(Class<T> clazz, String filter) {
BundleContext context = getBundle().getBundleContext();
ServiceTracker tracker = null;
try{
tracker = new ServiceTracker(context, context.createFilter("(&(" + Constants.OBJECTCLASS + "=" + clazz.getName() //$NON-NLS-1$ //$NON-NLS-2$
+ ")" + filter + ")"), null); //$NON-NLS-1$ //$NON-NLS-2$
tracker.open();
return (T) tracker.getService();
} catch (InvalidSyntaxException e) {
return null;
} finally {
if(tracker != null)
tracker.close();
}
}
getService(Location.class, Location.INSTALL_FILTER)