Using classes from a bundle inside CRXDE lite | Adobe Higher Education
Skip to main content
Level 6
October 16, 2015
Risolto

Using classes from a bundle inside CRXDE lite

  • October 16, 2015
  • 4 risposte
  • 1581 visualizzazioni

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.

Questo argomento è stato chiuso alle risposte.
Migliore risposta di Ratna_Kumar

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.

4 risposte

Ratna_Kumar
Ratna_KumarRisposta
Level 10
October 16, 2015

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.

smacdonald2008
Level 10
October 16, 2015

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? 

Level 6
October 16, 2015

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

Now the bundle is working correctly.

 

Regards

 

Clive

smacdonald2008
Level 10
October 16, 2015

That is great news!!