AEM Run modes and Order Resolution

Run modes allow you to configure AEM for different environments, for example there is an Author and Publish run mode that comes OTB with AEM.  You can also add your own run modes, an example of which would be prod, uat or dev. These run modes can be used to represent testing and production environments.

How to View Run Modes

Navigate to the System Overview - http://localhost:4502/libs/granite/operations/content/systemoverview.html

The run mode is shown under the instance section.

Or go to the Sling Settings screen - http://localhost:4502/system/console/status-slingsettings

The run modes are shown in the last property.

How to set the run mode.

In order of resolution/precedence (the top will override the bottom),  the ways to set the run mode are shown below.

  1. sling.properties file
  2. -r option using jar command
  3. system properties (-D)
  4. Filename detection

Sling.properties file

The sling properties file can be found here - crx-quickstart\conf

You can add in a new property in the file, for example

sling.run.modes=author

Further reading about sling properties can be found here
https://sling.apache.org/documentation/configuration.html

-r option using jar command

If your running the AEM  the jar from the command line you can pass in the run mode via -r property.

java -jar aem-pubish-p4503.jar -r prod

Setting System property (-Dsling.run.modes)

System properties in Java are passed in via the command line,  however in AEM it is more common to set the run mode via the start script.

Open the start script in crx-quickstart\bin and scroll to the bottom, we can see where Dsling.run.modes is set.

To change this we can change the CQ_RUNMODE variable. Multiple run modes can be set by using a comma to separate them.

Filename detection

This is when you rename the AEM jar file to supply the run mode. However this has limitations. For example rename the AEM jar to aem-publish-p4503.jar to set the publish run mode, For more details you can see.

AEM Setup Part 1 : How to Install AEM Locally on Windows.
Part 1 of how to setup AEM covers setting up the AEM instance on your local machine

Deploying AEM Jar to application Server

If you are deploying the AEM jar to an application server .eg tomcat, websphere you can set the sling.run.modes property in properties file within the WEB-INF folder.