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.
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
The Composum Browser contains a couple of tools which you could use to speed up
synchronization between the JCR and your local IDE.
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.
The package manager itself has a REST API
that allows installing a package e.g. via a script.
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
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
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