Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Unable to import annotations package

Avatar

Former Community Member

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.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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

View solution in original post

4 Replies

Avatar

Employee Advisor

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

Avatar

Former Community Member

I've tried restarting the AEM server but the problem persists.

Avatar

Level 10

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.

Avatar

Correct answer by
Employee Advisor

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