Create AEM Multi Module Project using Eclipse

The focus of this tutorial is to learn how to AEM Multi Module Project and build it using maven. This tutorial is intended for AEM beginners who are facing issue in setting up their eclipse work space.

I personally like this tutorial very much as it clear lot of basics and recommend it for advanced developers also to go through it once. If you want to learn how to create or setup a new project in AEM from scratch and how to sync data between eclipse and crxde .

After completing this tutorial. you will have a clear understanding of:-

Pre-requisites for creating a mvn archetype Project:-

Install AEM Plugin from MarketPlace

  • Open Eclipse
  • Go to Help available in top bar.
  • Select Eclipse Marketplace
  • Search for AEM.

install aem plugin in eclipse

  • Click install.
  • On next screen Click Confirm.
    confirm aem plugin in eclipse
  • Accept terms and condition and click Finish.
  • Press OK on Warning.
    cofirm warning aem eclipse plugin
  • Once installation is completed. Restart Eclipse.

Create AEM multi module project using aem plugin

  • Open Eclipse.
  • select File -> New project -> Select AEM Sample Multi-Module Project.
    create new aem multi-module project eclipse
  • Click Next to select Archetypeselect project location and archtype
  • Click Next to configure AEM Archetype project
    configure archtype properties for aem project
  • If you expand Advanced option.
    • You can see that Name maps to artifactName and appsFolderName
    • Package maps to location org/training folder in your .m2 directory. during maven build your code will be copied at this location.
    • Artifact Id maps to cssId. It is the unique id for your project.
  • Click Next for server configuration. Select don’t deploy on server as we are going to use maven command for deployment.
  • Click Finish.
  • Your project structure should look like below screenshot.aem mvn multi-module project structure

Note: – It will take around 5-10 minutes for setting up your project structure.
AEM maven multi-module project structure

Modify pom.xml to add profiles

  • Open pom.xml of aemcq5tutorials.ui.apps and aemcq5tutorials.ui.content.
  • Go to profiles section and add below code.

<profile>
<id>aemcq5tutorials-author</id>
<properties>
<crx.host>localhost</crx.host>
<crx.port>4502</crx.port>
<crx.username>admin</crx.username>
<crx.password>admin</crx.password>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<executions>
<execution>
<id>install-custom-package</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<targetURL>http://${crx.host}:${crx.port}/crx/packmgr/service.jsp</targetURL>
<userId>${crx.username}</userId>
<password>${crx.password}</password>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Similarly we can add or publish enviroment.

Note: – If you don’t have any profile with the name you are trying to build then you will get warning message during build “the requested profile could not be activated because it does not exist”.

Build AEM Multi Module project using Maven

  • On your local system go to aemcq5tutorials pom.xml location.
  • Open command prompt and run below command
mvn clean install -P aemcq5tutorials-author

build mvn multi module project

  • Once build is success

maven multi module build success

  • Go to localhost:4502/crx/de
  • You can see you project structure is mapped to crxde from eclipse.
    crxde project structure

Note:- If your project is in installed state in Felix console and getting import error “javax.inject;version” . Then add below line in your project core pom.xml


<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<!--
<Embed-Dependency>
artifactId1,
artifactId2;inline=true
</Embed-Dependency>
--><!-- Add below line -->
<Import-Package>javax.inject;version=0.0.0,*</Import-Package>
<Sling-Model-Packages>
org.training.aemcq5tutorials.core
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>

Click Here to Learn How to create project in aem using maven archetype command.

Also see how to sync content from crxde to eclipse using vlt plugin.

Spread the love

Leave a Reply to Sheetal Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.