Tuesday, 28 March 2023

Setting Up Local Dev environment for AEM.

Development Tools

Name

Link

Intelij Idea

https://download.jetbrains.com/idea/ideaIU-2020.3.2.win.zip

InteliVault

https://plugins.jetbrains.com/plugin/7328-intellivault/versions/stable/44439

Vault Cli

https://repo1.maven.org/maven2/org/apache/jackrabbit/vault/vault-cli/3.5.4/vault-cli-3.5.4-bin.zip

Maven

https://dlcdn.apache.org/maven/maven-3/3.9.1/binaries/apache-maven-3.9.1-bin.zip

OpenJDK 11

https://download.java.net/java/ga/jdk11/openjdk-11_windows-x64_bin.zip

Git Client

https://github.com/git-for-windows/git/releases/download/v2.40.0.windows.1/Git-2.40.0-64-bit.exe

ACS Commons

https://github.com/Adobe-Consulting-Services/acs-aem-commons/releases

 Note : I am using older version of Intelij Idea as its compatible with InteliVault plugin. There are other plugins like Brackets, AEM Sync for VSCode, REpo tool etc.. But InteliVault is my personal choice to use with IntelijIdea as it supports configuring multiple environments like local, DEV, QA, etc..

Create a separate folder in your local drive with name something like Development Tools and download all the above tools in it.

 

Setting Up Maven

1.       Extract the contents of “apache-maven-3.x.x.zip” and copy path to bin folder.

2.       Go to Environment Variables by opening run prompt using

Windows+R, type below command and hit Enter

Sysdm.cpl,3

3.       Go to Path under System Variables field and add new path to the list, pointing to bin directory of apache-maven,


 

Setting Up JDK

1.       Extract the contents of “openjdk-11+xx_windows-x64_bin.zip” and copy path to /bin folder.

2.       Follow Step 2 and 3 as given under section “Setting up Maven” above.

Setting up Git SSH

Once successfully installed, we can set up SSH keys to our GitHub account. Open Git bash and follow below steps for same.

a.       Check if keys already exist

ls -al ~/.ssh

b.       If not, generate using below command

ssh-keygen -t ed25519 -C youremail@mail.com

keep everything default, hit enter.

c.       Now check if they are generated using same command

ls -al ~/.ssh

d.       Start the SSH Agent in background

eval $(ssh-agent -s)

e.       Add the generated SSH-private keys to ssh-agent

ssh-add ~/.ssh/id_ed25519

f.        Copy contents of the id_ed25519.pub to clipboard

clip < ~/.ssh/id_ed25519.pub

g.       Add the copied contents to your Github/Bitbucket account

Click profile photo -> Settings -> Click the tab “SSH and GPG Keys” -> Click “New SSH Keys” and paste the content in text field using CTRL+V, then click Add SSH Key.

h.       If asked, input your password again, Done.

you can use the git commands from git bash or from the built-in command line terminal of Intelij IDE.

 

Few Standard practices working with repository.

·         Never push commits directly to master or develop branches.

·         Always work on the tip of master/develop branch. Always keep your branches updated with master/develop branch using git pull origin <parent-branch>.

·         Always create a new branch for assigned story/task/ticket, make all commits for fixes/enhancements on that branch only. Branch names should follow standard naming conventions depending upon the task feature, bugfix, hotfix, spike etc.

·         Commits should have a relevant messages, no generic messages.

 

Setting up Intelivault with Intelij

1.       Open IntelijIdea downloaded from above link, and go to File -> Settings -> Plugins. Click onbutton and select Install Plugin from disk… option



2.       Once installed, it will start appearing under Tools section. As highlighted in the below screenshot, set the path of vault bin directory to the field Vault Directory.



Multiple repositories pointing to multiple instance can be configured with InteliVault plugin, as shown in the screenshot above.

Once configured, you can now pull/push the CRX contents to codebase and vice a versa




Apart from this, Intelij Idea provides additional simplified way to deal with Version controlling, maven building with different goals and profiles.

 

Creating AEM Project

Once you have maven configurations done, please open commandline and check the maven installation status using below command

 

Once a maven is configured, you will need a setting.xml file to be in the .m2 folder of your machine. Its location is

C:\Users\<your machine name>\.m2

Please drop a settings.xml file to above location from below Github location

https://gist.github.com/anupammaiti/28011e1dab34d409ed980df8e18e54b4

 

Once this is done, open command prompt, point it to a directory where you want to create a new project. Please paste below command to the command line and hit enter,

mvn -B archetype:generate -D archetypeGroupId=com.adobe.aem -D archetypeArtifactId=aem-project-archetype -D archetypeVersion=30 -D appTitle="My Site" -D appId="mysite" -D groupId="com.mysite.aem" -D artifactId="mysite-aem-project" -D version="0.0.1-SNAPSHOT" -D aemVersion="6.5.5" -D includeDispatcherConfig=n -D includeExamples=n  -D frontendmodule=general

This will create a new project in given directory.

The above command may not be a best suited for your project requirement or AEM instance version, therefore the archetypeVersion, aemVersion, frontEndModule, includeExamples etc. Please refer below documentation by Adobe for same

https://experienceleague.adobe.com/docs/experience-manager-core-components/using/developing/archetype/overview.html

Also check, the archetype version compatibility with your running AEM version.

Once your command is finished creating a project, you can open it in Intelij IDE. First time when you open the project, you may have to wait for few moments for dependencies to be resolved and imported/downloaded from maven/adobe repo.

Once project start appearing on Intelij, please hit the command from command line

mvn clean install

to check if project is getting built successfully and everything is OK.

 

Debugging AEM Project with Intelij Idea

Make sure you have started your local AEM instance in debug mode. you can use below command to run your AEM instance in debug mode

java -Xmx2048M -agentlib:jdwp=transport=dt_socket,address=8888,server=y,suspend=n -jar <name of your AEM JAR file>

where, address is the port number you will configure in below steps

a.       From Menu bar, click Run -> Edit Configurations…

b.       A pop-up with open, click on PLUS button, and select Remote option, give a name to your configuration, set the port number and module class-path to your project’s core module.

 



Rest things can be kept default. click Apply and then Ok

c.       once you complete above configurations, the toolbar will show available debug configurations. Select your’s and click on


 icon to start listening to local AEM instance.

d.       As soon as you hit the page containing component, using java class where you had added a breakpoint, the debugger will stop on that break point. Then onward, you can debug your code.

 

Checkout my other blog - Integrate the WCM core components with AEM codebase

No comments:

Post a Comment

Dispatcher configurations in AEM - 2

 Dispatcher configuration 1. The Dispatcher configuration is stored in the dispatcher.any text file. 2. The file contains a series of single...