@Reference Annotation not working in aem Fiddle Script for JSP and servlets
It complains
Compilation errors in /apps/acs-tools/components/aemfiddle/fiddle/fiddle.java: Line 15, column 396 : Only a type can be imported. org.osgi.service.component.annotations.Reference resolves to a package
Found out one solution and gets the work done:
getService(MyService.class);
static <T> T getService(Class<T> serviceClass) {
BundleContext bContext = FrameworkUtil.getBundle(serviceClass).getBundleContext();
ServiceReference sr = bContext.getServiceReference(serviceClass.getName());
return serviceClass.cast(bContext.getService(sr));
}
Any better way to do it?