April 16, 2020
Estimated Post Reading Time ~

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 issues in setting up their eclipse workspace.
I personally like this tutorial very much as it clears a lot of basics and recommends it for advanced developers also to go through it once. If you want to learn how to create or set up 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:-
How to install the AEM plugin in eclipse.
How to create an AEM multi-module project using aem plugin.
Modifying pom.xml for custom profiles.
Build an AEM multi module project using maven.

Pre-requisites for creating an mvn archetype Project:
Maven should be installed.
AEM instance should be up and running.
Install AEM Plugin from MarketPlace

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

Click install.
On the next screen click Confirm.


Accept terms and conditions and click Finish.
Press OK on Warning.

Once the installation is completed. Restart Eclipse.
Create an AEM multi module project using aem plugin

Open Eclipse.
select File -> New project -> Select AEM Sample Multi-Module Project.

Click Next to select Archetype
Click Next to configure AEM Archetype 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 the server as we are going to use a maven command for deployment.
Click Finish.

Your project structure should look like the below screenshot.

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 the profiles section and add the 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 a 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


Once build is success


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


Note: If your project is in the 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>


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.