Composum Blog

various aspects of the Composum world

Automatic Content Synchronization during Development

We discuss various possibilities to speed up Sling development with automatic content synchronization from the content you edit in your IDE, if possible within seconds.

Hans-Peter Störr
04.01.2023

Introduction

When you are developing an application for Apache Sling or AEM, it is often very helpful to set up a speedy synchronization of content you're developing in your IDE (such as .content.xml files creating resources, .html, .jsp, .css and .js files) into the JCR repository of your local development environment. Even if a local build and deployment takes only one minute, that can still considerably slow down your workflow, especially if you're doing frontend development. Fortunately, there are quite a number of possibilities to do that. The goal of this article is to give some pointers on how to achieve that, and give some examples for some methods.

Some general possibilities

This collects some pointers, though I didn't try out many of them. See also here for the opposite process of downloading from the JCR.

Deployment from the build process

If you're working with Apache Maven as a build system, you will probably want to set up automatical deployment of the generated artifacts from your local build process to your Sling or AEM instance via maven plugins like the Apache Sling Maven Plugin or the newer Content Package Maven Plugin. Both have goals for automatic deployment, the Content Package Maven Plugin also has a download goal to update the stored content from JCR.

If your project is small, that might suffice, but if it is larger, that will take a couple of minutes, so it could be a painful interruption to your development process, and you might want speedier alternatives transferring only what was changed.

Incremental deployment to JCR

If you're working with npm for your frontend development anyway, and are working with AEM, aemsync is an interesting tool that can help you. Not sure whether you can use it with the Composum Package Manager that's often used on plain Sling.

For IntelliJ there is the (payed) AEM Support plugin that can update content in AEM. For eclipse, there is documentation on the Sling site.

SourceUpdateServlet in Composum

The Composum Browser contains a couple of tools which you could use to speed up synchronization between the JCR and your local IDE.

  1. When editing content in the browser or with other tools that modify JCR, the browser itself can be a valuable tool in that it provides an XML view that can be used to copy out content of one page into a .content.xml, and download a ZIP file containing .content.xml etc. files compatible with the VaultFS format used in packages without going through the lengthier process of creating a package and downloading that.
  2. The package manager itself has a REST API that allows installing a package e.g. via a script.
  3. For updating content there is a SourceUpdateServlet.java that allows updating an existing content tree.

As example we give some scripts that can be used to upload content trees via the command line, and it's also possible to use these as external tools in e.g. IntelliJ, where you can select a directory in IntellJ and either update the sources in IntelliJ from the JCR content or update the JCR content from the directory - just by calling the appropriate external tool entry from the context menu.

Using the File System Resource Provider

Alternatively to downloading and uploading into JCR, the Apache File System Resource Provider provides the possibility to map filesystem directories temporarily directly into the JCR. Of course, this works only for local servers, while many of the other methods in this page can be used to modify content of other remote servers, too.

Moreover, the Apache Sling Maven Plugin provides goals sling:fsmount and sling:fsunmount to automatically add/remove a configuration for such a mapping into a running sling server. So, configuring your Sling Launcher to take the content of the paths in the maven artifact you're currently working on directly from the filesystem (according to the artifacts filter.xml), might be as easy as calling

mvn -Dsling.url=http://localhost:8080/system/console sling:fsmount

That method has it's limits, though, since the filesystem does not provide all features of a JCR, but might be well worth a try.

Synchronization with WebDAV from IntelliJ

Sling can make the JCR accessible via WebDAV. IntelliJ supports (at Tools/Deployment) creating a WebDAV connection setting up aritrarily many mappings and uploading / downloading changes, even automatically.

Example configuration in IntelliJ:
Web server URL: http://localhost:9090/server/default/jcr%3aroot/
Mapping: Local path: /Users/hps/dev/composum/nodes/pckgmgr/src/main/resources/root/libs/composum/nodes/pckgmgr
Deployment path: /libs/composum/nodes/pckgmgr/
Web path: libs/composum/nodes/pckgmgr