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
  • 10220 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

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

Can you check your export packages in your bundle?

I don't think it has anything to do with the OSGi service, it that wouldn't exist you would get a NullPointer somewhere.

To me when compiling the JSP it can't find the Java-class.

smacdonald2008
Level 10
October 16, 2015

What version of CQ are you using? 

This article - along with all community helpx articles have been tested many times - as well as tested by some of the AEM regular community members. I just did the persist one and it works. Here is the web page:

[img]Persist.png[/img]

Here is the Data persisted in the JCR - same data:

[img]Persist2.png[/img]

The question here is why can you not get this working? 

This error messge means that JSP cannot find the OSGi. Can you see if this is under the Service view. You have to be able to see this under the Service tab of the Felix OSGi console:

[img]Service.png[/img]

maximilian_queh
Level 2
October 16, 2015

I have solved the issue concerning "Uncaught SlingException org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP: "

The problem is, that I did other tutorials before and the Bundles have the same package structure like in this tutorial: http://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content.html (com.adobe.cq)

And the problem is, that OSGI is package centric and cannot resolve the service in another bundle with the same package structure.

The solution is either to stop other bundles with the same package structure or to change the package structure of the current bundle.

Then everything works fine

Max

maximilian_queh
Level 2
October 16, 2015

Hi smacdonald2008,

would it be possible to post the solution here - I get exactly the same exception and actually I don't know what I am doing wrong.

Bundle is "Active", Service is listed but JSP can't compiled to a Servlet.

It would be great if you could post the solution.

Thanks a lot!!!

Max

October 16, 2015

Get it, i will do that according to that aritcle. Thank you so much.

smacdonald2008
Level 10
October 16, 2015

Package up your app - including the bundle and page - bundle up everything and email me the ZIP file at scottm@adobe.com. Follow this article to bundle that app - including the OSGi. I want to see your app:

http://helpx.adobe.com/experience-manager/using/packaging-cq-applications-contain-osgi.html

October 16, 2015

Hi,

Yes, i did it literally according to this article but, always encounter that error.

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.