3
votes

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?

3
Not a solution.. but are you doing a Maven build on all your instances.. author and publish?Suren Konathala
Yes, I am doing the maven build typically to two publish instances and an author instance.Vortexcalm
As a sanity check, remove the java files from the folder(save them somewhere), do a maven build, and check your pages where you are using Sightly. Obviously you should see errors on the page. If not then check the locations where you have the java sources. If you do see errors then it is a good sign that maven is picking the right files. Put them back and try. Also check if the Java files have right package names to make sure they are being packaged in the right spot.Suren Konathala

3 Answers

2
votes

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.

1
votes

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.

0
votes

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