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

How to compile a java class created in a component definition

Avatar

Level 2

Hi All,

How can I compile a java class created under a component definition. I am trying to use a WCMUse class in sightly to get an object from java class which I created under the component definition. I tried another way of creating a WCMUse java class in eclipse multi-module project but it is throwing "No use provider could resolve identifier: com.pro.eLearning.core.impl.servlets.CourseDisplay" error. Please help me.

Please do let me know if you need anymore information.

Best Regards

M. Ramana Reddy

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@Reference will only work with your OSGI Component java files. you won't be able to use @Reference in your AEM component classes that is extending WCMUse.

To get OSGI Component reference in WCMUse class, do the following:

- Runal

View solution in original post

9 Replies

Avatar

Level 10

See the following community article. It talks about how to create a Sightly component that compiles a Java class that uses com.adobe.cq.sightly.WCMUse.

See:

Creating your first Adobe Experience Manager Sightly component

Avatar

Level 2

Thanks for the reply. Actually if the java file don't have any @Reference annotation. it is working correctly. But If add that annotation then it is giving a compilation error "

Only a type can be imported. org.apache.felix.scr.annotations.Reference resolves to a package Reference cannot be resolved to a type

"

Is there anything wrong I am doing here??? please help me.

Avatar

Correct answer by
Community Advisor

@Reference will only work with your OSGI Component java files. you won't be able to use @Reference in your AEM component classes that is extending WCMUse.

To get OSGI Component reference in WCMUse class, do the following:

- Runal

Avatar

Level 10

it means that the interface that you have used with @reference is not present. 

are you using your own service or CQ service with @Reference ?

Avatar

Level 2

I am using Adobe API' @Reference annotation. This error is coming when I use my OSGi bundle class file also BSLOKI.

Avatar

Level 2

Thanks for reply Runal. Sorry for the silly question. How can i get FullyClassifiedBundleComponentClassPath. Right now I am having a class in org.company.module.classname. I am trying to use like this.

SlingScriptHelper sling = getSlingScriptHelper(); <fully qualified classname> helloService = sling.getService(<fuly qualified class name>.class);

Correct me if I am wrong. Are the FullyclassifiedBundleComponentClassPath and fullyQualifiedClassPath different?

please help me. Thanks.

Avatar

Community Advisor

Yup its fullyQualified and not classified :) that was the typo mistake thanks for correcting.

Glad it helped you.

- Runal

Avatar

Level 2

Runal.Trivedi wrote...

Yup its fullyQualified and not classified :) that was the typo mistake thanks for correcting.

Glad it helped you.

- Runal

 

 

I have my custom method in the service interface and implemented that method in the implementation class. But It is throwing error like the custom method undefined for the service. Is there anything I have to do here. There is a method in the interface which was created while creating the project by the aem plugin. If I call that method it i working like a charm. But not the methods added by me. Is there any process for adding the methods to the service interface??

Your Patience and Help are much appreciated.

Avatar

Employee

If you create a Java-class at component level, make sure the package is like apps.yourproject.components.yourcomponents.

It must match the location of the Java-class.