Example development tasks - bartoszWesolowski/aem-tips GitHub Wiki

Example development tasks

A list of example development tasks that an AEM dev should be able to solve.

Installation and configuration

Run AEM with custom run mode for given environment

Run mode to be used: integration, instance type: author

Possible solutions:

  • Add sling.run.modes parameter to sling.properties file under <aem-install-dir>/crx-quickstart/conf
  • Set CQ_RUNMODE env variable to author,integration and start AEM with a start script (<aem-install-dir>/crx-quickstart/bin)
  • Add -r parameter to start command: java - jar quickstart.jar -r author,integration (can also be -Dsling.run.modes=)

Create package with configuration for a service author and publish:

  • PID com.day.cq.wcm.core.impl.VersionManagerImpl with property versionmanager.createVersionOnActivation=true for run modes
  1. Under /apps/project-dir create two nodes: config.author and config.publish (sling:Folder)
  2. Under each create node com.day.cq.wcm.core.impl.VersionManagerImpl of type sling:OsgiConfig and add property with correct value

Notes:

  • config will be used only if all run modes of the directory matches instance run modes
  • if multiple the config with most matching run modes is used

Troubleshooting

Create custom log file

When debug port is not enabled for an instance a easy way to debug selected services is to create custom log file with low debug level (changing debug level for all log files makes it hard to use as AEM logs a lot of messages when processing requests).

This task can be done via config deployment (if logger will be added also to the project repository) or from web console.

Services to be added

  1. Logger for selected classes/pacakges - new service instance using service factory org.apache.sling.commons.log.LogManager.factory.config
  • Apache Sling Logging Logger Configuration
  • org.apache.sling.commons.log.LogManager.factory.config-custom-logger
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:OsgiConfig"
    org.apache.sling.commons.log.pattern="{String}{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}"
    org.apache.sling.commons.log.names="[com.aemexampless.aem.services]"
    org.apache.sling.commons.log.file="logs/custom-log-file.log"
    org.apache.sling.commons.log.level="trace"
    org.apache.sling.commons.log.additiv="true" />

  1. Optionally Apache Sling Logging Writer Configuration can be created to control log file rotation
  • config factory
  • number of files to keep
  • strategy for removing old files