This conversation has been locked due to inactivity. Please create a new post.
This conversation has been locked due to inactivity. Please create a new post.
I've been trying to get a Sightly component working in AEM 6.1 by following the documentation here
Apparently, in order to have my Java "use" class be visible to my Sightly component, all I need to do is use the full Class name (i.e. including the package) in my "use" statement.
<div data-sly-use.listChildren="com.t4g.aem.impl.usebeans.ListChildrenUseBean"><!-- Markup --></div>
I've followed the directions and built and deployed my bundle. My compiled class is in there (I cracked the JAR to make certain.) and still, the Sightly engine cannot find my class. I've tried WCMUse and WCMUsePojo. I've tried alternate syntaxes in the Sightly markup (I've found variants here and there). Nothing seems to works for a bundled use bean.
If I drop the same class into the component and update the package to match, everything works fine.
I'd love to know:
Thank you for your help.
The exception I get is:
org.apache.sling.scripting.sightly.SightlyException: Identifiercom.t4g.aem.impl.usebeans.ListChildrenUseBean cannot be correctly instantiated by the Use API[...]Caused by: org.apache.sling.scripting.sightly.SightlyException: Cannotfind class com.t4g.aem.impl.usebeans.ListChildrenUseBean.
The "not quite full" exception trace is as follows (it's really long, sorry):
org.apache.sling.scripting.sightly.SightlyException: Identifier com.t4g.aem.impl.usebeans.ListChildrenUseBean cannot be correctly instantiated by the Use API at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:91)at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:89)at apps.noSightly.components.listchildren.SightlyJava_listchildren.render(SightlyJava_listchildren.java:41)at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderUnit.render(RenderUnit.java:52)at org.apache.sling.scripting.sightly.impl.engine.SightlyScriptEngine.evaluateScript(SightlyScriptEngine.java:95)at org.apache.sling.scripting.sightly.impl.engine.SightlyScriptEngine.eval(SightlyScriptEngine.java:83)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)at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:533)at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:44)at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:77)at com.day.cq.personalization.impl.TargetComponentFilter.doFilter(TargetComponentFilter.java:96)at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilterWithErrorHandling(WCMDebugFilter.java:182)at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:149)[...]Caused by: org.apache.sling.scripting.sightly.SightlyException: Cannot find class com.t4g.aem.impl.usebeans.ListChildrenUseBean.at org.apache.sling.scripting.sightly.impl.compiler.SightlyJavaCompilerService.getInstance(SightlyJavaCompilerService.java:126)at org.apache.sling.scripting.sightly.impl.engine.extension.use.JavaUseProvider.getPOJOFromRepository(JavaUseProvider.java:125)at org.apache.sling.scripting.sightly.impl.engine.extension.use.JavaUseProvider.provide(JavaUseProvider.java:112)at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:87)... 248 more
[Cross-posted on http://Stackoverflow.com ]
Solved! Go to Solution.
Views
Replies
Total Likes
The component cannot find the Java. See this community artilce that will teach you how to setup everything so that Sightly finds the Java: Creating your first Adobe Experience Manager Sightly component.
Views
Replies
Total Likes
Hi,
Just to confirm, Are you using Sling Model in developing Sightly component?. If yes, just make sure you have a correct maven project configuration for the Sling model.
For more details:
https://helpx.adobe.com/experience-manager/using/creating-sightly-component.html
Modify the POM files to successfully build the OSGi bundle. In the POM file located at C:\AdobeCQ\model\bundle, add the following dependencies.
In the following POM file, notice this plugin element.
https://helpx.adobe.com/experience-manager/using/sling_models.html
---Jitendra
Views
Replies
Total Likes
Have you also verified the OSGI manifest of the bundle that the package "com.t4g.aem.impl.usebeans" is declared to be exported in export-package header ?
Views
Replies
Total Likes
This looks indeed like an issue that you are not "exporting" your package.
Views
Replies
Total Likes
The component cannot find the Java. See this community artilce that will teach you how to setup everything so that Sightly finds the Java: Creating your first Adobe Experience Manager Sightly component.
Views
Replies
Total Likes
Thanks for all your answers.
I'm afraid that tutorial above doesn't solve my issue. but indeed the missing link was that the Java class wasn't visible to OSGi because it wasn't in the bundle manifest.
To correct that, I had to add the details for all of the imported and exported packages to the org.apache.felix:maven-bundle-plugin entry in the bundle projects pom.xml
Here's what my pom entry looks like:
<plugin><groupId>org.apache.felix</groupId><artifactId>maven-bundle-plugin</artifactId><extensions>true</extensions><configuration><instructions><Bundle-SymbolicName>com.us.aem.sightly-stuff-bundle</Bundle-SymbolicName><Export-Package><!-- Let's export our primary package -->com.us.aem.impl.usebeans<!-- By default, don't export any other packages --></Export-Package><Import-Package><!-- JSR 250 && 330 -->javax.annotation;version=0.0.0.1_007_JavaSE,javax.inject,<!-- JEE Servlet -->javax.servlet,javax.servlet.http,<!-- Sling -->org.apache.sling.api,org.apache.sling.api.resource,org.apache.sling.auth.core,org.apache.sling.jcr.api,com.day.cq.commons,org.apache.sling.api.request,com.adobe.cq.sightly,com.day.cq.wcm.api,org.slf4j</Import-Package></instructions></configuration></plugin>
Typically, I use Felix SCR annotations on my classes (e.g. @Component, @Service, @SlingServlet) which allows the SCR Maven plugin to take care of adding my imports and classes to the manifest. In this case, because there are no such annotations on the use bean, so you must to do it by hand. It seems self-evident in retrospect, but it's a step that none of the tutorials out there (including the one linked to in the "solution" above) mention. My compiled class was in the bundle all along but wasn't exposed by the manifest.
Thanks,
Taylor
P.S. Before seeing these responses, I got the solution from an answer I kindly received from swathi07 in another thread. Thanks to all who responded.
Hi,
Just a remark: by default all java packages containing the string "impl" are not exported by the bundle plugin. It is best practice not to export the implementation classes but only the interfaces. In the case of Sightly it's different, but then I wouldn't put them into an "impl" package.
Jörg
Views
Replies
Total Likes
Views
Likes
Replies