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

Using classes from a bundle inside CRXDE lite

Avatar

Level 6

If I have a bundle imported into AEM using http://localhost:4502/system/console/bundles and I do not have any Interfaces exposed as Services but my bundle is active and has the package with my class in the export packages.

 

The examples I have come across in the documentation use something like the below example

 

com.adobe.cq.KeyService keyService = sling.getService(com.adobe.cq.KeyService.class);

 

However if the KeyService interface is not listed with a service id then when it is called a null pointer exception is raised.

 

Can one gain access to a class in the JSP if it is not shown with a service id. In my case I have implemented my interface and use @Component and @Service on the implementation class but it does not show any service id in the Web Console screen.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Clive,

You cannot/ever call the bundle from JSP page, if the Interface is not listed under Service Id in web console even it is in the Active state.

As Scott stated, the very best practice to create a OSGI bundle is that first you have to define/create interface and implement the corresponding interface from Class and best way to build the bundle through maven like discussed in this article (http://helpx.adobe.com/experience-manager/using/first-osgi.html)

Regards,
Ratna Kumar.

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi Clive,

You cannot/ever call the bundle from JSP page, if the Interface is not listed under Service Id in web console even it is in the Active state.

As Scott stated, the very best practice to create a OSGI bundle is that first you have to define/create interface and implement the corresponding interface from Class and best way to build the bundle through maven like discussed in this article (http://helpx.adobe.com/experience-manager/using/first-osgi.html)

Regards,
Ratna Kumar.

Avatar

Level 10

When you create a bundle for AEM - its best practice to define an interface and then an implementation class - as shown in the KeyService article.

http://helpx.adobe.com/experience-manager/using/first-osgi.html

If you do not create an interface - an exception occurs. If you follow the article - you will get the correct results. 

[img]Key.png[/img]

Do not use CRXDE lite to create bundles - use Maven!  In this article - we step you through exactly how to setup  Maven so that you can build AEM bundles. We step you through it in detail. 

Are you doing anything different from the instructions specified in the article? 

Avatar

Level 6

Thank you both for the great advise.. I had not set the maven-scr-plugin correctly. 

Now the bundle is working correctly.

 

Regards

 

Clive