Getting started with Apache Sling - Part 2

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

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

Prerequisites

  • OpenJDK for Java 1.8
  • Git
  • Maven (I'm using 3.3.9)
  • The Eclipse IDE for Java EE Developers (I'm using Neon)
  • The Sling Launchpad

Note: This post will walk you through the steps required to install the OpenJDK for Java 1.8. And, this post will walk you through the steps required to install Git, Maven and the Eclipse IDE.

Getting Started

The Apache Sling docs include a short introduction to Sling called Discover Sling in 15 minutes. Once you grok the basic examples, they recommend you take a look at the espblog sample.

The espblog sample

The espblog sample uses server-side JavaScript to implement a simple blogging application that includes support for file attachments.

The first thing we need to do is to clone Sling's Gitub mirror. Let's start by creating a new directory in our Eclipse workspace:

cd ~/Eclipse/Neon/workspace
mkdir apache-sling-source
cd apache-sling-source    

And then we can clone the Sling framework:

git clone https://github.com/apache/sling.git

The Eclispe IDE

Now we're ready to import the espblog sample into the Eclispe IDE, select 'File -> Import...':

Select 'Existing Maven Projects', then click the Next button:

Select the espblog samples's root directory, click the Finish button, then take a look at the project's structure in the Project Explorer:

Before we build and install the espblog bundle we need to start the Sling Launchpad:

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

Now we're ready to build and install the espblog bundle, in Eclipse's Project Explorer right click on the project's pom.xml and select 'Run As -> Maven Build...':

Enter the following goals: clean install -P autoInstallBundle, then click the Run button.

In the Eclipse's Console view, you should see output like:

[INFO] Bundle installed
[INFO] -----------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] -----------------------------------------------------------------
[INFO] Total time: 24.968 s
[INFO] Finished at: 2017-04-03T15:34:32+10:00
[INFO] Final Memory: 36M/121M
[INFO] -----------------------------------------------------------------

The espblog sample also requires the path-based-rtp bundle, so import the project into Eclipse and then build and install the bundle (just follow the same steps we followed for the espblog project).

In your browser navigate to http://localhost:8080/content/espblog/*.html and the espblog's welcome page will be displayed:

Note: Bertrand Delacretaz's SlideShare presentation titled Rapid JCR application development with Sling includes coverage of the espblog sample:

The Publick Blogging Platform

If you are looking for a more advanced Apache Sling sample, then take a look at this post on Nate Yolles blog:

The Slick Blogging Engine

Another advanced Apache Sling sample is the Slick Blogging Engine:

References: