AEM 6.1 | Java Classes with in components | Community
Skip to main content
June 29, 2016

AEM 6.1 | Java Classes with in components

  • June 29, 2016
  • 3 replies
  • 6326 views

Hi All,

We have a requirement to have classes related to components to be with in the component folder it self. And after I compile a java class in CRXDE lite where will be the class files gets generated? and how can we access this?

Also if we have to write JUnit test classes for the same how do I do it? We are using AEM 6.1 and sightly for our components

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

3 replies

smacdonald2008
June 29, 2016

That requirement is not best practice when working with AEM. Best practice is to place Java into OSGi bundles and build OSGi bundles using Maven. See this article on how to use Maven  Archetype 10: 

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

For community members reading this thread and using an earlier version of AEM (ie 6) - see: 

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

Hope this helps

smacdonald2008
June 29, 2016

Sightly Java should definitely go into an OSGi bundle - see this article: 

https://helpx.adobe.com/experience-manager/using/creating-sightly-component.html

thilaks18944609
November 2, 2017

Has this changed. The Adobe document recommends writing the java class within the component if the use class is specific to the component. here is the link HTL Java Use-API

Any comments?

smacdonald2008
November 2, 2017

Never use CRXDE lite to write Java Classes for an HTL Component - always build your Java using a Maven Project and deploy to AEM. See Adobe Experience Manager Help | Creating an Adobe Experience Manager HTML Template Language component that uses the WCMU…

kautuk_sahni
Community Manager
Community Manager
June 30, 2016

Hi 

You do you want tohave "classes related to components to be with in the component folder it self" ? It is not a recommended way.

Please have a look at :- https://helpx.adobe.com/experience-manager/using/first-arch10.html

This article covers :-

  • how to use Maven Archetype 10 command to create an AEM project
  • how to use Sightly and Sling Models
  • how to use JUNIT tests within Java files
  • how to use a scheduler service
  • how to use Sling Servlets
  • how to use a basic event handler
  • how to perform component inheritence
  • how to reference partial page files in a Sightly page component
  • how to work with ClientLibs in a Sightly component

 

Some Reference article for Junit Testing :- 

Link:- http://aempodcast.com/2015/testing/unit-testing-wcmuse-classes-using-mockito/#.V3Svn_l97RY

Link:- http://wcm.io/testing/aem-mock/usage.html

Link:- https://docs.adobe.com/docs/en/aem/6-1/develop/components/hobbes.html

 

I hope this will help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni