Vortexcalm
Vortexcalm

Reputation: 41

AEM 6.1 Sightly Java class does not update on build

I have recently started using Sightly in AEM 6.1, which allows the Java files to be located in the same folder as the component and use the WCMUse class. However, I am noticing that whenever I do a Maven build that involves a change to one of those Java files that the page functionality operates as if the Java class had not been changed, though the Java file in the crx does include the changes. As a workaround I have been been able to modify the Java file in the crx, save it, then modify it back and save again in order to update the functionality, but I do not have that capability on all of my instances.

Anybody have an idea how to force the recompile of the Sightly Java within the components either during or following the build?

Upvotes: 3

Views: 2619

Answers (3)

Vortexcalm
Vortexcalm

Reputation: 41

Bambara actually helped me get to the answer that I needed. It turns out the /var/classes folder holds the compiled sightly files, but it doesn't naturally recompile on build. Deleting that folder on build, then running a page that uses the sightly code forces a recompile and shows the new functionality.

Upvotes: 1

Cris Rockwell
Cris Rockwell

Reputation: 904

Hopefully others can answer why this happens and how to avoid it. Having faced this a number of times, I'm beginning to think placing Java code into the component folders is not a very good idea. Using a maven multi-module project with a Services/Core bundle, then all Java code could go there. Calling it from the view just requires using the fully qualified classname (including the package). Placing the Java into the services bundle has the following benefits

  • Allows the classes to be extended. For some reason compilation was unpredictable when extending classes from component folders.
  • Easier IDE setup. Java classes in component folders in the view module have a Sling specific folder structure, so getting IDE's to provide code assist requires extra effort.
  • Sling folder conventions follow URI practices and might have dashes, Java packages cannot have dashes... import apps.my-cool-project.components.pages.base.Header; // won't compile

Upvotes: 0

Bambara
Bambara

Reputation: 608

A few things to validate:

1- Do you change the version of the software when doing a maven build/deploy? Sometime if your zip or jar does not have -SNAPSHOT in it AEM won't update the code when maven deploys.

2- there a /var/classes/sightly in CRX/DE that you can delete compiled classes, I think even in the system console there is an entry

Hope this help.

Upvotes: 2

Related Questions