Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Java class extends WCMUse compile error (Only a type can be imported com.adobe.sightly.WCMUse resolves to a pakcage)

Avatar

Level 2

Hi all,

    I wrote a Java class which extends WCMUse in AEM6. It compiles fine on AEM6. However, when I move my code to AEM5.6.1, and compile the code, I got the following error message:

"Only a type can be imported com.adobe.cq.sightly.WCMUse resolves to a package"

"WCMUse cannot be resolved to a type"

I thought maybe my local instance of AEM 5.6.1 doesn't have the necessary service pack. So I installed both security pack 1 and service pack 2 on my local instance of AEM 5.6.1. Restart the server, and I still got the same compiler error when I click Tools > Compile within crx/de in AEM 5.6.1.

Please let me know if you know how to resolve this issue.

Thanks,

Kai

1 Accepted Solution

Avatar

Correct answer by
Level 10

These are sightly APIs which were introduced from 6.x onwards.

Although there is feature pack of sightly available in 5.6.1 but that is just to see sightly preview and wont support sightly apis completely

To get code working you need to use AEM 6+, Check release notes here https://docs.adobe.com/docs/en/aem/6-0/release-notes.html

View solution in original post

15 Replies

Avatar

Correct answer by
Level 10

These are sightly APIs which were introduced from 6.x onwards.

Although there is feature pack of sightly available in 5.6.1 but that is just to see sightly preview and wont support sightly apis completely

To get code working you need to use AEM 6+, Check release notes here https://docs.adobe.com/docs/en/aem/6-0/release-notes.html

Avatar

Level 2

If there is no way to use WCMUse in AEM5.6.1, what is the recommended way to implement custom code in AEM 5.6.1? Do I re-implement my Java code in JSP? Or is there other way to trigger Java code in AEM 5.6.1?

Avatar

Level 10

You do not need Sightly to invoke a backend Java Service from a component's JSP. WCMUse is only used for Sightly, not for Java services that can be invoked from JSP logic. 

Read this article, it will give you the basics:

com.adobe.cq.KeyService keyService = sling.getService(com.adobe.cq.KeyService.class);
keyService.setKey(10) ; 

See:

https://helpx.adobe.com/experience-manager/using/first-osgi.html

Avatar

Level 2

The reason why I create a class that extends WCMUse not only because I want to trigger the Java class via sightly, but also because WCMUse allow me to use getPageManager() and getResourceResolver(), so the Java code can interact with Node in AEM. How do I do that without extending WCMUse in AEM 5.6.1?

Thanks,

Kai

Avatar

Level 2

edubey wrote...

These are sightly APIs which were introduced from 6.x onwards.

Although there is feature pack of sightly available in 5.6.1 but that is just to see sightly preview and wont support sightly apis completely

To get code working you need to use AEM 6+, Check release notes here https://docs.adobe.com/docs/en/aem/6-0/release-notes.html

 

The feature pack works in AEM 5.6.1. But I am trying to find a way to implement it without the feature pack. Any suggestion?

Avatar

Level 10

As I mentioned earlier sighlty was introduced 6.0 onwards

Sightly API which u are using (WCMUse) will not be available in 5.6.1 and thus you cannot use

You have to use AEM 6+

Avatar

Level 2

I understand that, my question is, how do custom Java class interact with AEM node (read, write) prior to AEM 6?

Avatar

Level 10

You can write osgi service to read data or java  class

For osgi service alot of articles are available there, do check

http://blogs.adobe.com/kmossman/2012/04/osgi-sling-service-example.html

Avatar

Level 2

Can you share an example of Java class creating new node or reading existing node in AEM?

Avatar

Level 2

Thanks for the link. I found this line on the article:

Note:

Calling jcrUtils.getRepository() is used from an external Java application. If you are using the JCR API from within an OSGi bundle, do not use this method. For information about using the JCR API from within an OSGi bundle, see Querying Adobe Experience Manager Data using the JCR API.

 

I believe the link I need is this one. 

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

Avatar

Level 10

You want to use JCR API within an OSGi bundle to do this use case. See this community artilce - where both read and write operations occur: 

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

Hope this helps clear up your doubts. 

Avatar

Level 10

You are correct - i referenced same artilce

Avatar

Level 2

On the article, it started the project with Maven, POM, Eclipse. However, I would like to do everything within CRX/DE. I don't seems to be able to get the @Reference (Apache Felix SCR annotation) to work if I simply code it in CRX/DE.

The "import org.apache.felix.scr.annotations.Reference;" give a compiler error:

  "Only a type can be imported org.apache.felix.scr.annotations.Reference resolves to a package"

If I remove the import line,  then I get the following compiler error on "@Reference":

Reference cannot be resolved to a type

If I remove the @Reference, then I get a NullPointerException error because resolverFactory is never defined.

Can I resolve all these problems in CRX/DE without transferring my work to Maven,Eclipse,POM.xml?

Avatar

Level 10

Its not recommended to use crxde for java files or osgi bundle

You have to write code in any IDE ( can use eclispe or Intelj) where you will have all api and IDE auto completion and then deploy to AEM as an osgi bundle.