AEM 6.1 | Java Classes with in components

Avatar

Avatar

CQ_learner

Avatar

CQ_learner

CQ_learner

29-06-2016

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

Replies

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

29-06-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

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

29-06-2016

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

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

Avatar

Avatar

kautuk_sahni

Community Manager

Total Posts

5.6K

Likes

1.0K

Correct Reply

1.1K

Avatar

kautuk_sahni

Community Manager

Total Posts

5.6K

Likes

1.0K

Correct Reply

1.1K
kautuk_sahni
Community Manager

29-06-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

Avatar

Avatar

thilaks18944609

Avatar

thilaks18944609

thilaks18944609

02-11-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?

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

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

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

02-11-2017

We will log a bug for that document!

Avatar

Avatar

thilaks18944609

Avatar

thilaks18944609

thilaks18944609

02-11-2017

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

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

02-11-2017

YEs  -- when working with AEM HTL component - you can use these development techniques:

1 - WCMUsePojo -- see this article:  Adobe Experience Manager Help | Creating an Adobe Experience Manager HTML Template Language componen...

2 - Sling Models -- see this article:  Creating a custom Touch UI Grid Component for Adobe Experience Manager

3 - JS USE API - see: Creating a Tab layout component for Adobe Experience Manager

Hope this helps ....