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

The type com.book.rental.modal.Book cannot be resolved. It is indirectly referenced from required .class files

Avatar

Level 2
 
 

Hi 

I created a maven based project and then created a OSGI bundle and uploaded in the bundle section (Using AdobeCQ 5.6). I am able to access the services and print a simple "Hello Welcomet o OSGI World". When i am trying to implement .getBookList() method where it has to feth all the latest books from repository and add to a Book (a pure pojo class with get set metods. It contains book details like book name, title,created date and description etc etc) object and pass on to UI. 

In JSP my code is 

<%@ page language="java" import="java.util.*,java.lang.*" %>
<%@ page import="com.pavan.book.*,com.pavan.adobe.*,com.book.rental.modal.*" %>

   <%
    try{

            com.pavan.adobe.BookRentalServices services =   sling.getService(com.pavan.adobe.BookRentalServices.class);

              out.println("HeloooooooooooooooooogetLatestBooks() ooooo"+services.getMessage()); // Printing perfect out put. "Welcome to OSGI World"

             out.println("HeloooooooooooooooooogetLatestBooks() ooooo"+services.getLatestBooks());// Throwing error. Please see the error below.
}catch(Exception e){

    out.println(e);

}
%>

org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 31 in the jsp file: /apps/rental/components/pages/home/home.jsp The type com.book.rental.modal.Book cannot be resolved. It is indirectly referenced from required .class files 28:     // BookServices service = resource. adaptTo(BookServices.class); 29:      com.pavan.adobe.BookRentalServices services =   sling.getService(com.pavan.adobe.BookRentalServices.class); 30: out.println("Helooooooooooooooooooooooo"+service.getMessage()); 31:     out.println("HeloooooooooooooooooogetLatestBooks() ooooo"+services.getLatestBooks()); 32: }catch(Exception e){ 33: 34:     out.println(e);

 

I am not able to understand how to resolve this error. Please help out.

Please let me know if any one require more information

 

1 Accepted Solution

Avatar

Correct answer by
Level 6

In the bundle that holds the class com.book.rental.modal.Book, make sure that it is exported in the OSGi-manifest. Otherwise, there is no bundle that will present this class to the system.

/Ove

View solution in original post

5 Replies

Avatar

Correct answer by
Level 6

In the bundle that holds the class com.book.rental.modal.Book, make sure that it is exported in the OSGi-manifest. Otherwise, there is no bundle that will present this class to the system.

/Ove

Avatar

Level 2

Thanks OVE, The error got resolved. Let me work further and see if things goes on fine.

Avatar

Level 10

For future reference see: http://scottsdigitalcommunity.blogspot.ca/2013/02/querying-adobe-experience-manager-data.html?m=0

This community article demonstrates a similar use case. That is, create a POJO in an OSGi bundle that can retrieve JCR data. Then how to successfully deploy the bundle, how to call the service, and finally how to display the data in a page component.  

Avatar

Level 2

Thanks, The links is very useful.

Sorry for asking this dumb question. 

I am trying to get respositroy details by following way.

    repository = JcrUtils.getRepository("http://192.168.0.104:4503/crx/server");
    session = repository.login( new SimpleCredentials("admin", "admin".toCharArray())); 

   Node    root = session.getRootNode();.

but i am getting Null pointer exception and unable to acces the repository. When i try the same program using a standalone java i am able to read the repository. 

When i went through the url u gave i see you are accessing the data in different way. Can you please let me know what the wrong in accessing the way i am doing.

Thanks in advance.

Avatar

Level 10

There are no dumb questions.

When using the JCR API code within an OSGi bundle -- you cannot get a session object using this Java code:

 repository = JcrUtils.getRepository("http://192.168.0.104:4503/crx/server");
 session = repository.login( new SimpleCredentials("admin", "admin".toCharArray())); 

You need to get a session using this Java code:

//Invoke the adaptTo method to create a Session used to create a QueryManager
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);

 

If you try the 1st way from within an OSGi bunlde-- you will get a Java exception. You can only use this code in a Java app that is outside of the OSGi service layer.

For example -- here is a Java Swing app that gets AEM JCR Data using getRepository():

http://scottsdigitalcommunity.blogspot.ca/2013/11/developing-java-swing-application-that.html

 

But when you want to use the JCR API from within an OSGi bundle, you have to use session = resourceResolver.adaptTo(Session.class);
 

as explained here: http://scottsdigitalcommunity.blogspot.ca/2013/02/querying-adobe-experience-manager-data.html.

Hope this helps,

Scott