Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

AEM 6.1 | Java Classes with in components

Avatar

Level 4

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

8 Replies

Avatar

Level 10

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

Avatar

Level 2

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?

Avatar

Level 10

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 componen...

Avatar

Level 2

Thanks, That document was confusing me. But writing JavaScript Use-API is valid right?

Avatar

Administrator

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