Sling Models is a way to create model objects which are automatically mapped from Sling objects, typically resources but also request objects.
This article explains how to use sling models in AEM. But, If you want to use Sling models with AEM 6.2, you might encounter some dependency issues.
Recently I faced a problem when my AEM project stopped working. The project was created using Maven archetype 10. It was working fine until I was on AEM 6.1. When I tried deploying it to AEM 6.2, the bundle was not coming to Active state. Later while debugging, I found out that it was not able to find a particular dependency. I was seeing something like below in the console.
javax.inject,version=[0.0,1) -- Cannot be resolved
After some debugging, I was able to resolve the issue. If you are facing the similar issue, you need to add the below dependency to your pom file.
This is it. Sling Models code should work on AEM 6.2 now.
Hope it helps !! 🙂
While working on one of a complex requirements in our project, we felt the need to continuously analyze the flow. Though, logs are of good help but we wanted to analyze the complete flow . In this scenario, debugging feature in IDE becomes very handy. Software Stack being used :
- CQ Server : AEM 5.6.1
- IDE : IntelliJIdea 12.0
First We need to start our CQ instance in debug mode. We can do so by starting the AEM in debug mode by running the following command :
java -jar cq5-author-4502.jar -fork -forkargs -- -Xdebug -Xrunjdwp:transport=dt_socket,address=59865,suspend=n,server=y -Xmx1520m -XX:MaxPermSize=512m -XX:-UseSplitVerifier
We need to first open the socket from where all the JVM communication will happen. We need to specify the port number while starting the instance. Socket specifies the entry point for all the communication that happens in JVM. Every communication will happen via Socket. In above command,
address=59865 is creating the socket for us. In IDE, we need to setup a remote connection for CQ and specify the same port no as mentioned while starting CQ. Follow the below steps to setup a remote connection in IntelliJIdea.
- Go to Run panel (top of the window) and select Edit configuration.
- Select Defaults and click on “+” to add new configuration. List of all the options will appear. Select “Remote” from that list.
- Enter the details in the window as per your need. Specify the same port number which was used while starting the CQ instance in debug mode.
- Click on “OK” to save the configuration.
Below is the screenshot for the reference.
Add breakpoints in the java files which you want to debug by double clicking on the line and start newly created configuration in Debug mode.
1. While starting the AEM instance, make sure JVM has enough heap size for running CQ server, otherwise it will fork the JVM and parameters will not be passed to the forked jvm. Use -fork -forkargs – option to ensure that the command line parameters gets passed to the jvm.
2. If you are using java 7 , make sure to specify the -XX:-UseSplitVerifier parameter to avoid the unwanted strict verification errors while debugging the bundle.
Hope it helps !! 🙂