Ir al contenido principal

Creating an AEM application using Maven and Adobe's archetype

In this tutorial, I show how to use Maven and Adobe's archetype to create an application from scratch and then build it and deploy it into AEM, also, the last part of the video shows how to do the same process using a Maven container using Docker, above is the vid and below you will find some useful notes.
  1. 1.


  2. 2.

    What is Maven

    • Maven is among many things a build automation tool which uses xml files called Project Object Model or POM files to describe different things about a project like what dependencies the project has, how to build and deploy a project and so on.
    • For dependency management, Maven uses two types of artifact repositories which can be categorized as:
    • Remote, which are typically publicly available on the internet like Maven Central or privately available inside your company’s internal network.
    • And local repositories, which are typically inside a .m2 folder inside your local file system where maven runs and it’s used for caching and storing local builds.
  3. 3.

    Maven Archetypes

    • Maven archetypes can be used for creating new applications or modules without going through the hassle of configuring each piece of the app by hand, like the appropriate libraries or the plugins required, the different profiles to execute and many other different things needed to provide a seamless development experience. In our case adobe’s archetype will take care of even creating some mock content, example classes, components, configurations and other stuff for us so that we can start tinkering with our new app right away.
      mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate "-DarchetypeGroupId=com.adobe.granite.archetypes" "-DarchetypeArtifactId=aem-project-archetype" "-DarchetypeVersion=19" "-DarchetypeCatalog=" "-DgroupId=co.dlighthouse.aem.firstapp" "-DartifactId=aem-first-app" "-Dversion=0.1.0-SNAPSHOT" "-Dpackage=co.dlighthouse.aem.firstapp" "-DappsFolderName=first-app" "-DconfFolderName=first-app" "-DartifactName=First App Example" "-DcomponentGroupName=First App Example" "-DcontentFolderName=first-app" "-DcssId=first-app" "-DpackageGroup=first-app" "-DsiteName=First App Example" “-DoptionAemVersion=6.4.0”
    • Adobe’s archetype will generate a multi module project, with modules for the bundle that contais all the java classes like Sling models and sling servlets, another module for creating the AEM package that contains the AEM components and a final one with the site and assets. There are two final modules used for testing.
  4. 4.

    Building and deploying

    • For building and deploying the application into an Author instance running locally using the 4502 port
      mvn clean install -PautoInstallPackage -Padobe-public
  5. 5.

    Docker and Maven

    • If you recall from the video, maven uses a local .m2 folder for the local repository and that whenever a dependency is missing there it will try to download it from the remote repository. When using Docker containers and given that they are isolated from each other if we just try to execute the maven commands it will try to download everything every time you use a new container.
    • To avoid that we need to use Docker Volumes which will allow us to define a local folder on your machine so that docker can use it for storing the artifacts downloaded by maven and so that they can be reused from different containers.
    • For defining a volume when starting a container you just need to add a -v parameter followed by a mapping, in which you specify the local folder in which the files are or should be located, a colon and the internal container’s folder
      docker run ... -v LOCAL-FOLDER:CONTAINER-FOLDER ...
    • If you want to check the current contents of a folder using the container you can use bash instead of the maven command at the end
      docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/workdir -w /usr/src/workdir -v "$(pwd)"/.m2:/root/.m2 maven:3.6.1-jdk-8 /bin/bash
    • For creating the app you can use docker and append the complete maven command that uses the archetype after that
      docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/workdir -w /usr/src/workdir -v "$(pwd)"/.m2:/root/.m2 maven:3.6.1-jdk-8 mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate "-DarchetypeGroupId=com.adobe.granite.archetypes" "-DarchetypeArtifactId=aem-project-archetype" "-DarchetypeVersion=19" "-DarchetypeCatalog=" "-DgroupId=co.dlighthouse.aem.firstappdocker" "-DartifactId=aem-first-app-docker" "-Dversion=0.1.0-SNAPSHOT" "-Dpackage=co.dlighthouse.aem.firstappdocker" "-DappsFolderName=first-app-docker" "-DconfFolderName=first-app-docker" "-DartifactName=First App Docker Example" "-DcomponentGroupName=First App Docker Example" "-DcontentFolderName=first-app-docker" "-DcssId=first-app-docker" "-DpackageGroup=first-app-docker" "-DsiteName=First App Docker Example" “-DoptionAemVersion=6.4.0”
    • You can acomplish the same thing here by appending just the build MAven command after the docker one
      docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/workdir -w /usr/src/workdir -v "$(pwd)"/../.m2:/root/.m2 maven:3.6.1-jdk-8 mvn clean install -Padobe-public -PautoInstallPackage
  6. 6.


Entradas populares de este blog

Create a custom AEM workflow process step with a dialog

In this tutorial I talk about how to create a custom workflow step process with an additional dialog for configuring it, above is the vid and below you will find some useful notes. 1. Pre-reqs Have access to an Adobe Experience Manager instance. Have Maven installed, understand how it works and also understand how to use Adobe's archetype, you can watch my video about maven here: Creating an AEM application using Maven and Adobe's archetype 2. What is an AEM Workflow and workflow model Workflows allow you to automate different tasks inside AEM by defining a s

Creating Docker containers for Adobe Experience Manager

This is a Docker tutorial for creating a docker image for the Galen framework, above is the vid and below you will find some of the steps followed. Adobe experience manager is a content management system which in a nutshell is an application that allows us to create web sites to be consumed by end users. You might be familiar with other such applications like wordpress or drupal which serves the same purpose A typical deployment would be comprised of two AEM instances, the author instance used for creating and modifying content, the publish instance which serves the content and finally we have a dispatcher which is a static web server used for caching, load balancing and some security purposes. We can configure an AEM instance to work as an author or publish instance by either changing the file name

Creating a Mongo replicaset using docker: Mongo replicaset + Nodejs + Docker Compose

This is a Docker tutorial for creating a Mongo replica set using docker compose and also a couple more containers to experiment with the replica set, above is the vid and below you will find some of the steps followed. Steps Pre-reqs Have node.js installed And docker installed (make sure you have docker-compose as well) Create a container for defining configurations for a mongo instance Create a container for setting up the replica set Create a simple node app using expressjs and mongoose (A modified version from the previous video ) Create a docker-compose file with the mongo and setup containers and two additional containers for experimenting with the replica set Build, Run and experiment with your new containers Create a dockerfile for the first mongo container (not really needed but you could configure more stuff if needed) Include container with mongo preinstalled:  FROM mongo Create default/working directory:  WORKDIR /usr/src/configs Copy mongo