Why OSGI service cannot be resolved to a type? | Community
Skip to main content
October 16, 2015
Solved

Why OSGI service cannot be resolved to a type?

  • October 16, 2015
  • 18 replies
  • 10178 views

According to this article http://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content1.html# , finally run happened below error. I look into this problem for one day but no way to fix it.

Anyone could help see this problem, thanks in advance.

persist.json.jsp

<%@include file="/libs/foundation/global.jsp"%> <%@ page import="org.apache.sling.commons.json.io.*,com.adobe.cq.*" %><% String first = request.getParameter("first"); String last = request.getParameter("last"); String phone = request.getParameter("phone"); String desc = request.getParameter("desc");com.adobe.cq.CustomerService cs = sling.getService(com.adobe.cq.CustomerService.class);int myPK = cs.injestCustData(first, last, phone, desc) ; //Send the data back to the client JSONWriter writer = new JSONWriter(response.getWriter()); writer.object(); writer.key("pk"); writer.value(myPK); writer.endObject(); %>

Error message:

13.10.2014 11:16:45.677 *ERROR* [127.0.0.1 [1413170205545] GET /content/testjcr/_jcr_content.persist.json HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught SlingException
org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 8 in the jsp file: /apps/jcrpersist/components/page/templateJCR/persist.json.jspcom.adobe.cq.CustomerService cannot be resolved to a type5: String phone = request.getParameter("phone"); 6: String desc = request.getParameter("desc"); 7: 8: com.adobe.cq.CustomerService cs = sling.getService(com.adobe.cq.CustomerService.class);9: 10: int myPK = cs.injestCustData(first, last, phone, desc) ; 11: at org.apache.sling.scripting.jsp.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92) at org.apache.sling.scripting.jsp.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) at org.apache.sling.scripting.jsp.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:421) at org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:312) at org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:290) at org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:277) at org.apache.sling.scripting.jsp.jasper.JspCompilationContext.compile(JspCompilationContext.java:501) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.prepareServlet(JspServletWrapper.java:427) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:486) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:265) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:87) at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:465) at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171) at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463)

OSGI bundle:

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ratna_Kumar

It worked for me in One go - I think it cannot find the Bundle from JSP. Please make sure to include the required dependencies and build the bundle as mentioned in the article.

18 replies

October 16, 2015

I using the Adobe Experience Manager, Version 6.0.0.20140509 and run it model as "cq-author-4502.jar". i chekc the tab "OSGI" under it the menu "service", it is well and nothing incorrectly. pleas see below screenshot or attachment:

 

The most weird point is never happen the exception also in JSP page could call the OSGI service according to this article example http://helpx.adobe.com/experience-manager/using/first-osgi.html

It's really make me confused.

October 16, 2015

Get it ,i send a email to you, please check it.

smacdonald2008
Level 10
October 16, 2015

Just tested this article on AEM 6:

http://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content1.html

It works as expected:

[img]AEM6Persist.png[/img]

The custom service that you built in the above link successfully saves the posted data into the JCR:

[img]AEM6Save.png[/img]

I am very curious as to why you are not getting these results. Email me at scottm@adobe.com. I can setup a connect session with you. I want to see what is happening. In the email - paste a link to this thread and in the subject line put community code. 

Also - when you build the OSGi using Maven - as shown in the article - make sure your POM contains the code that is shown in the article. If you follow along - you can literally copy and paste the POM from the article into your POM. It all works. 

Here is a tip - try to restart AEM too. See if that helps. 

smacdonald2008
Level 10
October 16, 2015

The article was written and tested on AEM 5.5, and 5.6.x.  The screen shot above is 5.6. 

In the articles - we put in the CQ versions at the start of the articles. See:

[img]Version.png[/img]

As these community articles are tested for AEM 6 - we will state that in the Article Summary section.

I will look into getting this to work on AEM 6. 

smacdonald2008
Level 10
October 16, 2015

I suspect that there is something in your development environment. I want to setup a connect session with you. By setting up a connect session - we will get to the bottom of this. I have tested this on 5.5, 5.6, 5,6,1 and 6 - and it works. 

October 16, 2015

hi,

Actually i mean this article example http://helpx.adobe.com/experience-manager/using/first-osgi.html is runing well in my localhost, but this article http://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content1.html always happen that error: can't compile JSP because com.adobe.cq.CustomerService cannot be resolved to a type.

The both have the same place is the template(jsp) involved the different OSGI servcie, but the second example why the interface cant be resolved to a type ?  so weird.

October 16, 2015

Hi,

I notice this article http://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content1.html# there is some mistake but i am not sure.

e.g., below the "strong" path i change it for "/apps/jcrpersist/components" because i notice never create fold sqlpersist and i guess it is a type mistake, right?

<ref>

The css.txt file contains the CSS file name: site.css. Likewise, the js.txt file contains the JS file name: jquery-1.6.3.min.js.

Add the files to the ClientLibs folder

 

  1. Right-click /apps/sqlpersist/components then select New, Node.

<ref>

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

Hi,

Your problem about the JSP compilation error looks like, that you miss the class

com.adobe.cq.CustomerService

I also don't know this class, at least it's not part of any GA release. In the webpage http://helpx.adobe.com/experience-manager/using/first-osgi.html you referenced above I also don't find any reference to this service. You should provide a class/interface there which is exported via any OSGI service in your AEM installation.

Kind regards,
Jörg

October 16, 2015

Thanks for your answer. And i deploy the bundle to OSGI container also start it with no any failure message. But i find no any dependency jar files were included into the bundle Jar, it only declare it's dependency in the pom file.

This error logged found in file {crx-quickstart}/logs/error.log and happened when first page form data was commit to persist.json.jsp to persist then fail to that.

Its make me confuse.

Ratna_Kumar
Ratna_KumarAccepted solution
Level 10
October 16, 2015

It worked for me in One go - I think it cannot find the Bundle from JSP. Please make sure to include the required dependencies and build the bundle as mentioned in the article.