Apache Sling is an open source, REST-based web framework, that makes it easy to build content-oriented applications (e.g., websites and related services).

Sling uses scripts (e.g., JavaScript, Groovy), template languages (e.g., HTL, Handlebars) or Java servlets to process HTTP requests and a Java Content Repository (Apache Jackrabbit Oak) as its data store. Sling uses Apache Felix to provide a dynamic runtime environment where code and content bundles can be loaded, unloaded and reconfigured at runtime.

The framework includes the Sling Launchpad which combines a number of infrastructure-level and application-level functions into a single integrated package.

In this post, we'll download and familiarise ourselves with the Sling Launchpad.

Note: Apache Sling is part of the Adobe Experience Manager (AEM) stack.

Prerequisites

  • OpenJDK for Java 1.8

Before we install the OpenJDK, its always a good idea to check for updates. So lets open a terminal session and run the following commands:

sudo apt update
sudo apt upgrade
sudo apt-get check
sudo apt-get autoclean

I'm running Elementary OS Freya (built on Ubuntu 14.04) and the OpenJDK for Java 1.8 has not been made a part of the official Ubuntu repositories. So we need to install the OpenJDK from a Personal Package Archive (PPA) repository.

To add the PPA repository, enter the following commands:

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update 

Now to install the Java JDK, enter the following command:

sudo apt-get install openjdk-8-jdk

If you have more than one Java version installed, you can use the following command to set the default Java version:

sudo update-alternatives --config java

And, the following command to set the default Java compiler:

sudo update-alternatives --config javac

You can check the Java version by running the following command:

java -version

You should then see output like:

openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-3~14.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)

And, you can check the Java compiler version by running the following command:

javac -version

You should then see output like:

javac 1.8.0_121

Note: Don't forget to update the JAVA_HOME environment variable in your .bashrc file:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Getting Started

Let's start by downloading the Sling Launchpad (a runnable JAR file) and then launching it:

java -Xmx1024M -jar org.apache.sling.launchpad-8.jar

The Sling Launchpad will take a few minutes to unpack the JAR file, install itself, and start up:

23.03.2017 15:35:42.566 *INFO * [main] Setting sling.home=sling (default)
23.03.2017 15:35:42.569 *INFO * [main] Starting Apache Sling in
  /home/rob/Eclipse/Neon/workspace/apache-sling/sling
23.03.2017 15:35:42.655 *INFO * [main] Starting launcher
23.03.2017 15:35:42.685 *INFO * [main] HTTP server port: 8080
...
23.03.2017 15:35:52.349 *INFO * [main] Startup completed

You now have a Sling Launchpad instance running on localhost listening on port 8080. In your browser navigate to http://localhost:8080/index.html and the Sling Launchpad's welcome page will be displayed:

Open a new browser tab and navigate to http://localhost:8080/system/console/bundles (use admin and admin if prompted to login) and Sling will display its Web Console:

In the Sling Web Console (on the OSGi Bundles page) we can see that the Sling Launchpad is comprised of 121 OSGi bundles. When launched as a standalone application the Sling Launchpad uses an embedded version of the Jetty HTTP servlet container.

The Launchpad also makes heavy use of the OSGi’s core and compendium (e.g., logging, configuration, metatype, event and declarative) services.

WebDAV Support

The Sling Launchpad also includes WebDAV support:

So you can access your content via the Eclipse IDE, your File Manager (e.g., Pantheon):

Or navigate to http://localhost:8080/.explorer.html and use the JCR Explorer:

What's Next

In the next post, we'll take a look at some of the samples included with the Apache Sling framework.

References: