Show Menu
TOPICS×

AEM Project Archetype

The AEM Project Archetype creates a minimal, best-practices-based Adobe Experience Manager project as a starting point for your own AEM projects. The properties that must be provided when using this archetype allow you to specify the names for all parts of this project as well as control certain optional features.

Why Use the Archetype

Using the AEM Project Archetype sets you on the path towards building a best-practices-based AEM project with just a few keystrokes. By using the archetype, all of the pieces will already in place so that while the resulting project is minimal, it already implements all of the key features of AEM so that all you have to do is build on top and extend.
Of course there are many elements that go into a successful AEM project, but using the AEM Project Archetype is a sound foundation and is strongly recommended for any AEM project.

Getting Started

The project archetype makes it easy to get started developing on AEM. You can take your first steps in a number of ways.
  • WKND Tutorial - For a great introduction to developing on AEM including how to leverage the archetype see the Getting Started with AEM Sites - WKND Tutorial for a practical example that walks you through using the archetype to implement a simple project.
  • WKND Events Tutorial - If you are particularly interested in single page application (SPA) development on AEM, be sure to check out dedicated WKND Events tutorial .
  • Download and start on your own! - You can easily download the current project archetype available on GitHub and create your first project by following the simple steps below .

What You Get Using the Archetype

The AEM Archetype is made up of modules:
  • : is a Java bundle containing all core functionality like OSGi services, listeners, and schedulers, as well as component-related Java code such as servlets and request filters.
  • : contains the
    /apps
    and
    /etc
    parts of the project, i.e. JS and CSS clientlibs, components, templates, runmode-specific configs, as well as Hobbes tests.
  • : contains sample content using the components from the ui.apps module.
  • : is a Java bundle containing JUnit tests that are executed server-side. This bundle is not to be deployed onto production.
  • ui.launcher
    : contains glue code that deploys the ui.tests bundle (and dependent bundles) to the server and triggers the remote JUnit execution.
  • :
    (optional)
    contains the artifacts required to use the general Webpack-based front-end build module.
  • :
    (optional)
    contains the artifacts required when using the archetype to create a SPA projects based on React.
  • :
    (optional)
    contains the artifacts required when using the archetype to create a SPA projects based on Angular.
The modules of AEM Archetype represented in Maven are deployed to AEM as content packages representing the application, the content, and the necessary OSGi bundles.

How to Use the Archetype

To use the archetype, you first need to create a project, which generates the modules in a local file structure as previously described . As part of project generation, a number of properties for your project can be defined such as project name, version, etc.
Building the project with Maven creates the artifacts (packages and OSGi bundles), that can be deployed to AEM. Additional Maven commands and profiles can be used to deploy the project artifacts to an AEM instance.

Creating a Project

To get started you can most simply use the AEM Eclipse extension and follow the New Project wizard and choosing
AEM Sample Multi-Module Project
to use a released version of the archetype.
Of course you can also invoke Maven directly.
mvn -B archetype:generate \ -D archetypeGroupId=com.adobe.granite.archetypes \ -D archetypeArtifactId=aem-project-archetype \ -D archetypeVersion=XX \ -D aemVersion=cloud \ -D appTitle="My Site" \ -D appId="mysite" \ -D groupId="com.mysite" \ -D frontendModule=general \ -D includeExamples=n
  • Set
    XX
    to the version number of the latest AEM Project Archetype.
  • Set
    aemVersion=cloud
    for AEM as a Cloud Service ; Set
    aemVersion=6.5.0
    for Adobe Managed Services , or on-premise. The Core Components dependency is only added for non cloud aem versions as the Core Components are provided OOTB for AEM as a Cloud Service.
  • Adjust
    appTitle="My Site"
    to define the website title and components groups.
  • Adjust
    appId="mysite"
    to define the Maven artifactId, the component, config and content folder names, as well as client library names.
  • Adjust
    groupId="com.mysite"
    to define the Maven groupId and the Java Source Package.
  • Lookup the list of available properties to see if there's more you want to adjust.
It is best practice to add the
adobe-public
profile to your Maven
settings.xml
file in order to automatically add repo.adobe.com to the maven build process.
An example POM can be found here .

Properties

The following properties are available when creating a project using the archetype.
Name
Default
Description
appTitle
Application title, will be used for website title and components groups (e.g.
"My Site"
).
appId
Technical name, will be used for component, config and content folder names, as well as client library names (e.g.
"mysite"
).
artifactId
${appId}
Base Maven artifact ID (e.g.
"mysite"
).
groupId
Base Maven group ID (e.g.
"com.mysite"
).
package
${groupId}
Java Source Package (e.g.
"com.mysite"
).
version
1.0-SNAPSHOT
Project version (e.g.
1.0-SNAPSHOT
).
aemVersion
6.5.0
Target AEM version (can be
cloud
for AEM as a Cloud Service ; or
6.5.0
,
6.4.4
, or
6.3.3
for Adobe Managed Services or on-premise).
sdkVersion
latest
When
aemVersion=cloud
an SDK version can be specified (e.g.
2020.02.2265.20200217T222518Z-200130
).
includeDispatcherConfig
y
Includes a dispatcher configuration either for cloud or for AMS/on-premise, depending of the value of
aemVersion
(can be
y
or
n
).
frontendModule
none
Includes a Webpack frontend build module that generates the client libraries (can be
general
or
none
for regular sites; can be
angular
or
react
for a Single Page App that implements the SPA Editor ).
languageCountry
en_us
Language and country code to create the content structure from (e.g.
en_us
).
singleCountry
y
Includes a language-master content structure (can be
y
, or
n
).
includeExamples
y
Includes a Component Library example site (can be
y
, or
n
).
includeErrorHandler
n
Includes a custom 404 response page that will be global to the entire instance (can be
y
or
n
).
If the archetype is executed in interactive mode the first time, properties with default values can't be changed (see ARCHETYPE-308 for more details). The value can be changed when the property confirmation at the end is denied and the questionnaire gets repeated, or by passing the parameter in the command line (e.g.
-DoptionIncludeExamples=n
).
When running on Windows and generating the dispatcher configuration, you should be running in an elevated command prompt or the Windows Subsystem for Linux (see issue 329 ).

Profiles

The generated maven project supports different deployment profiles when running
mvn install
.
Profile ID
Description
autoInstallBundle
Install core bundle with the maven-sling-plugin to the felix console
autoInstallPackage
Install the ui.content and ui.apps content package with the content-package-maven-plugin to the package manager to default author instance on localhost, port 4502. Hostname and port can be changed with the
aem.host
and
aem.port
user defined properties.
autoInstallPackagePublish
Install the ui.content and ui.apps content package with the content-package-maven-plugin to the package manager to default publish instance on localhost, port 4503. Hostname and port can be changed with the
aem.host
and
aem.port
user defined properties.
autoInstallSinglePackage
Install the
all
content package with the content-package-maven-plugin to the package manager to default author instance on localhost, port 4502. Hostname and port can be changed with the
aem.host
and
aem.port
user defined properties.
autoInstallSinglePackagePublish
Install the
all
content package with the content-package-maven-plugin to the package manager to default publish instance on localhost, port 4503. Hostname and port can be changed with the
aem.host
and
aem.port
user defined properties.
integrationTests
Runs the provided integration tests on the AEM instance (only for the
verify
phase)

Building and Installing

To build all the modules run in the project root directory, use the following Maven command.
mvn clean install
If you have a running AEM instance, you can build and package the whole project and deploy into AEM with the following Maven command.
mvn clean install -PautoInstallPackage
To deploy it to a publish instance, run this command.
mvn clean install -PautoInstallPackagePublish
Alternatively, to deploy to a publish instance, run this command.
mvn clean install -PautoInstallPackage -Daem.port=4503
Or to deploy only the bundle to the author, run this command.
mvn clean install -PautoInstallBundle

Parent POM

The
pom.xml
at the root of the project (
<src-directory>/<project>/pom.xml
) is known as the parent POM and drives the structure of the project as well as manages dependencies and certain global properties of the project.

Global Project Properties

The
<properties>
section of the parent POM defines several global properties that are important to the deployment of your project on an AEM instance such as user name/password, host name/port, etc.
These properties are set up to deploy to a local AEM instance, as this is the most common build that developers will do. Notice there are properties to deploy to an author instance as well as a publish instance. This is also where the credentials are set to authenticate with the AEM instance. The default admin:admin credentials are used.
These properties are set up so that they can be overridden when deploying to higher level environments. In this way the POM files do not have to change, but variables like
aem.host
and
sling.password
can be overridden via command line arguments:
mvn -PautoInstallPackage clean install -Daem.host=production.hostname -Dsling.password=productionpasswd

Module Structure

The
<modules>
section of the parent POM defines the modules that the project will build. By default the project builds the standard modules previously defined : core, ui.apps, ui.content, ui.tests, and it.launcher. More modules can always be added as a project evolves.

Dependencies

The
<dependencyManagement>
section of the parent POM defines all of the dependencies and versions of APIs that are used in the project. Versions should be managed in the Parent POM. Sub-modules like core and ui.apps should not include any version information.

Uber-Jar

One of the key dependencies is the AEM uber-jar . This will include all of the AEM APIs with just a single dependency entry for the version of AEM.
As a best practice you should update the uber-jar version to match the target version of AEM. For example, if you plan to deploy to AEM 6.4 you should update the version of the uber-jar to 6.4.0.

Core Components

The AEM Project Archetype of course leverages the Core Components.
The Core Components are installed in AEM automatically in the default runmode and used by the sample We.Retail site. In a production runmode (
nosamplecontent
) the Core Components are not available.
Therefore, in order to leverage the Core Components in all deployments, it is a best practice to include them as part of the Maven project.
Each release of the Core Components is generally followed by a release of the AEM Project Archetype so that the latest archetype uses the latest version of the core components.
However a new version of the archetype may not directly follow a new version of the Core Components, so you may wish to update the dependency on the Core Components to the latest version.
The core.wcm.components.examples are a set of sample pages that illustrate examples of the Core Components. As a best practice, when deploying a project for production use you should remove this dependency and subpackage inclusion.

Testing

There are three levels of testing contained in the project and because they are different types of tests, they are executed in different ways or in different places.
  • Unit test in core: This showcases classic unit testing of the code contained in the bundle. To test, execute:
    • mvn clean test
  • Server-side integration tests: These run unit-like tests in the AEM-environment, i.e. on the AEM server. To test, execute:
    • mvn clean verify -PintegrationTests
  • Client-side Hobbes.js tests: These are JavaScript-based browser-side tests that verify browser-side behavior. To test:
    1. Load AEM in your browser as you would to author a page.
    2. Open the page in Developer mode
    3. Open the left panel and switch to the
      Tests
      tab.
    4. Find the generated
      MyName Tests
      and run them.

Next Steps

So you have built and installed the AEM Project Archetype. What now? Well, the archetype is small, but consists of many examples of powerful AEM features configured according to recommended best practices. Use these are indicatory of how you can leverage these features in your project. For any project you likely need to: