March 30, 2020
Estimated Post Reading Time ~

Create Multiple Bundles in an AEM Maven Project

In AEM, Maven provides multi-module architecture.

What does it mean?
It means that we can have different modules like bundles and content(core,ui.apps) in a single project.

In this blog, we will discuss how can we create multiple bundles in the same project.
Initially, when we create an AEM Project, we always see two modules:
  1. Bundle
  2. Content
modules.PNG
Fig- Initial modules provided by maven-archetype

These modules are defined under parent Pom.xml.
modules.PNG
Fig- Modules configuration in parent Pom.xml

Problem Statement: I want to create multiple bundles in the same AEM Project. The use cases of doing this can be:
  • Need a bundle to run in publish instance only or need to deploy a bundle on the basis of specific locations.
  • Want to create multiple bundles in a single project on the basis of big functionalities like Login Module, Payment Module, etc.
Solution: It is very easy, you just need to follow the below steps:
  • Create the new bundle by just copying the existing bundle of a project.
add a new bundle.PNG
Fig - New Bundle created by copying the existing bundle

  • Rename the bundle1 ( i.e., test). Now In Pom.xml of Test bundle change the ArtifactID (Because artifact should be unique for each module of the project).
newbundle.jpg
Fig- Rename the copied bundle and change the artifact id in Pom.xml of a new bundle
  • Change the “Bundle-SymbolicName”  in the Test Module Pom.xml.
change-symbolic-name.jpg
Fig- Change the Bundle-SymbolicName in Pom.xml of Test Module
  • Add a new module in parent Pom.xml.
Fig- Adding Test Module in Parent Pom.xml
  • Content Pom.xml  contains the dependency of all the bundles, so we need to add the dependency of the new bundle(test-module) in this Pom.xml
add dependency.PNG
Fig- Add the dependency of Test Bundle in Content(ui.apps) Pom.xml
  • For deploying the bundles at any specific location we need to specify the location in the "target" (like install) and bundle ‘s groupId and artifactid in the embedded section.
deploy.PNG
Fig- Configuring the embedded section in Content(ui.apps) Pom.xml
  • Now you just need to build the code and you can find the bundle’s jar at the expected location as you configured in content Pom.xml in embedded section.
crx.PNG
Fig- Showing bundles at specific location
By following the above steps you can create n number of bundles in a single AEM project.


By aem4beginner

No comments:

Post a Comment

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