Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

OSGI Bundles and Archetype 10 Project

I was able to setup Archetype 10 type projects in Eclipse. I have few questions regarding the best practices followed during AEM development.

1. There is a core folder which I believe is used to write Java code. Now if a component which is present in apps folder refers a Java class, where should I write? Should it be present in core folder only?

2. The code inside the core folder is packaged into an OSGI jar and a bundle gets created. How should I go ahead if I want to create a 2nd bundle? Do I need to create a second Archetype 10 type project?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Sonal,

If you need to add just a different bundle, then you dont have to create a new project, instead you can just copy paste the core folder and make the few changes like

1. folder name

2. artifactId in the pom.xml

Now you can build both the bundles individually and deploy it on to the osgi container. 

If you add this bundle also to the parent pom.xml, then it also will be included when you build the whole project.

View solution in original post

9 Replies

Avatar

Level 10

Typically to use Maven - you can run this Maven Archetype command: 

mvn archetype:generate -DarchetypeRepository=http://repo.adobe.com/nexus/content/groups/public/ -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=multimodule-content-package-archetype -DarchetypeVersion=1.0.2 -DgroupId=com.aem.community -DartifactId=echoproject -Dversion=1.0-SNAPSHOT -Dpackage=com.aem.community -DappsFolderName=myproject -DartifactName="My Project" -DcqVersion="5.6.1" -DpackageGroup="My Company"

It generates this folder structure: 

You write OSGi Java code under the bundles folder - as shown in this illustration. 

Do not write OSGi code under content folder (which includes /Apps)

If you want to create additional services, add another Java class under bundle. You can create additional packages under bundle. You do not need to run another Maven Archetype project. 

If you are using 10 - see this GITHub project and Readme: 

https://github.com/Adobe-Marketing-Cloud/aem-project-archetype/blob/master/README.md

You are correct - in this 10 version - looks like you write code under the core folder. 

As in the older Maven archetype - you can add more packages and add new Java classes without creating a new Archetype project. 

So how will I create a second bundle? Do I need to create a new project?

One more ques. With AEM 6.1, (as a best practice) with which version of archetype project should I go ahead?

Avatar

Level 9

why do want to create second bundle?

Ideally Archtype10 is sufficient to create type AEM project.You can create as many classes you want under bundle folder.

-Kishore

If you see http://localhost:4502/system/console/bundles

then you will find that for Multi Site Management, WCM Workflow, there are multiple bundles deployed. So I thought that there might be instances where one might need to create multiple bundles.

Avatar

Level 10

  The AEM documentation uses: 

$ mvn archetype:generate \
    -DarchetypeRepository=https://repo.adobe.com/nexus/content/groups/public/ \
    -DarchetypeGroupId=com.day.jcr.vault \
    -DarchetypeArtifactId=multimodule-content-package-archetype \
    -DarchetypeVersion=1.0.2 \
    -DgroupId=my-group-id \
    -DartifactId=myproject \
    -Dversion=1.0-SNAPSHOT \
    -Dpackage=com.mycompany.myproject \
    -DappsFolderName=myproject \
    -DartifactName="My Project" \
    -DcqVersion="5.6.1" \
    -DpackageGroup="My Company"

The 10 has different starting files. All these Maven Archetype projects really do is give you a starting point that you can build from. 

Avatar

Level 10

1. Which version of archetype project should I go ahead? Archtype 10 is good to go 

2. The other bundle you are seeing are the default AEM jar files used for different modules and they are stored in \crx-quickstart\launchpad\felix

Avatar

Correct answer by
Community Advisor

Hi Sonal,

If you need to add just a different bundle, then you dont have to create a new project, instead you can just copy paste the core folder and make the few changes like

1. folder name

2. artifactId in the pom.xml

Now you can build both the bundles individually and deploy it on to the osgi container. 

If you add this bundle also to the parent pom.xml, then it also will be included when you build the whole project.

bsloki wrote...

Hi Sonal,

If you need to add just a different bundle, then you dont have to create a new project, instead you can just copy paste the core folder and make the few changes like

1. folder name

2. artifactId in the pom.xml

Now you can build both the bundles individually and deploy it on to the osgi container. 

If you add this bundle also to the parent pom.xml, then it also will be included when you build the whole project.

 

 

I did the same and cannot see the bundle deployed? Is that using Archetype10, we cannot use multiple modules? 

Our code structure:

The below does not create the bundle.

proj.core > src/main/java/org/myproj proj.it.launcher proj.it.tests proj.ui-apps pas.client [module we want to include] > src/main/java/org/myproj/pas > pom.xml pom.xml [Main pom]

If we move the "pas.client" sources to "proj.core", it is being included and we can use it in our main code.

proj.core > src/main/java/org/myproj > src/main/java/org/pas [module moved here] proj.it.launcher proj.it.tests proj.ui-apps pom.xml [Main pom]

But we wanted to have "pas.client" as a separate bundle. How can we do this?

The other option is see to create another Archetype10 project and include all our commonly used bundles (across projects) in this.

Avatar

Community Advisor

how are you building your pas.client ?

if you are trying to build from the parent pom.xml, have you added pas.client as the module to include in your parent pom.xml ?