March 14, 2020
Estimated Post Reading Time ~

Debugging in AEM

CQ5/AEM

While working on one of the complex requirements in our Adobe CQ5 / AEM project, we felt the need to continuously observe the flow. Though logs are of good help we wanted to analyze the complete flow. In this scenario, the 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 :
1
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 the above command, address=59865  is creating the socket for us. In IDE, we need to set up a remote connection for CQ and specify the same port no as mentioned while starting CQ. Follow the below steps to set up a remote connection in IntelliJIdea.
  1. Go to Run panel (top of the window) and select Edit configuration.
  2. Select Defaults and click on “+” to add a new configuration. A list of all the options will appear.  Select “Remote”  from that list.
  3. Enter the details in the window as per your needs. Specify the same port number which was used while starting the CQ instance in debug mode.
  4. 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.
Troubleshooting :
1. While starting the AEM instance, make sure JVM has enough heap size for running the 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 get 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.

*****
Per the Adobe documentation, to Debug an AEM app using eclipse, start AEM with this JVM parameter
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n

Option 1

For example, add it to the crx-quickstart/bin/start script CQ_JVM_OPTS environment variable
start
...
 
if [ -z "$CQ_JVM_OPTS" ]; then
            CQ_JVM_OPTS='-server -Xmx2048m -XX:MaxPermSize=256M -Djava.awt.headless=true -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n'
            ...
fi
-z means zero length. for example, if [ -z "$CQ_JVM_OPTS" ]; then means if $CQ_JVM_OPTS is empty. This check is for Option 2 described below.

Option 2

As documented in the start script comments, You can set the CQ_PORT and other variables using the command line when calling the start script. e.g.,
# The following variables may be used to override the defaults.
# For one-time overrides the variable can be set as part of the command-line; e.g.,
#
#     % CQ_PORT=1234 ./start
In this example, we’re setting the CQ_JVM_OPTS variable using the command line:
cd crx-quickstart/bin
CQ_JVM_OPTS='-server -Xmx2048m -XX:MaxPermSize=256M -Djava.awt.headless=true -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n' ./start





By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.