I am trying to write data to a JCR node from a custom form component in AEM 6.4.2, slightly following this tutorial: Adobe Experience Manager Help | Querying Adobe Experience Manager 6 data using the Sling getServiceR...
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.
Solved! Go to Solution.
Views
Replies
Total Likes
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.
Jörg
Views
Replies
Total Likes
That seems to be a glitch in the scripting bundle, which appears to happen every now and then. Restarting the scling scripting bundle or the complete instance should fix it.
(If you can reproduce this problem, please report it to the Adobe support.)
Jörg
Views
Replies
Total Likes
I've tried restarting the AEM server but the problem persists.
Views
Replies
Total Likes
Try this one that is built for AEM 6.4 and uses R6 annotations --
Adobe Experience Manager Help | Querying Adobe Experience Manager 6.4 JCR data
PS - the article you referenced was for 6.0/6.1.
Views
Replies
Total Likes
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.
Jörg
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies