JCR Installer Search Path Priority

We faced a problem where a project we were working on wanted to use features in the cq-6.3.0-featurepack-10262-1.2. We ran into an issue where the 6.3.0-featurepack package contains configurations to Demandware. The reason this was an issue is because our project had configuration nodes for Demandware as well. One solution would have been to uninstall the 6.3.0-featurepack but this was not an option. How do you give higher precedence to your package configurations to the same services without deleting the other package? How do you handle this conflict? One answer we found came from editing the Apache Sling JCR Installer configuration (PID: org.apache.sling.installer.provider.jcr.impl.JcrInstaller).

The Apache Sling JCR Installer scans the JCR repository for artifacts and provides them to the OSGI installer. In addition every node of type sling:OsgiConfig is provided as a configuration to the installer. These statements come straight from the documentation found here. The configuration that we found was the key to solving our conflicting node problem was the Search Paths list.

The default Search Paths contains two values: /libs:100, /apps:200. The first portion is the path that the Installer watches. The number that is separated from the path with a colon is the weight of that path, or how much priority the resources found under that path takes. Let’s say that you have OSGi configurations in your target project folder at the following path: /apps/my-project/config. So if you want these configurations to take effect, you would just have to add to the above list in the Installer Search Path configuration: /apps/my-project:300. The 300 value is arbitrary and does not have to be 100 points higher than the subsequent values. As long as the number is higher than 200, it will take higher precedence.

By adding our project path to the Apache Sling JCR Installer configuration, we were able to tell the Installer to take the configurations in our target project without having to uninstall the 6.3.0-featurepack. An elegant fix to a potentially complicated problem.