In order to write data to the JCR, I need to obtain a Session object which I can get through a ResourceResolverFactory object that's declared with an @Reference annotation. To use the @Reference annotation, I need to import org.apache.felix.scr.annotations.Reference in my Java code. I've included the dependencies listed in the tutorial in my parent/pom.xml file and rebuilt the project with the following maven command:
mvn clean install -PautoInstallAllPackage
Despite including and building those dependencies, I get this error in my Java file:
Caused by: org.apache.sling.scripting.sightly.SightlyException: Compilation errors in apps/project/components/content/foo/Foo.java:
Line 28, column 846 : Only a type can be imported. org.apache.felix.scr.annotations.Reference resolves to a package
What could be causing this problem? Is there a way to verify that the dependencies are installed on the system? I also tried using the newer OSGi R7 annotations instead of the older Felix ones and I run into the same issue. Can someone help me resolve this issue? Thanks.
The import class is "org.apache.felix.scr.annotations.Reference", and this is an SCR annotations; these annotations are build time annotations and typically processed by the maven-scr-plugin. Therefor this class is not available during runtime.
You are using this annotation in a class which you expect to be compiled during AEM runtime, but this does not work. To avoid issues like this I would recommend to develop and build all Java classes in an IDE, build them via maven and deploy them in an bundle into AEM.