How to include a core module package from one site in another site's core module? | Community
Skip to main content
Level 2
January 3, 2022
Solved

How to include a core module package from one site in another site's core module?

  • January 3, 2022
  • 2 replies
  • 1353 views

I have an AEM project where a certain component uses the following Java class: /core/src/main/java/com/mysite/core/util/MyClass.java.

 

I also have a different site that uses a separate AEM Project Archetype. I would like to use MyClass.java in the core module of the second site, however I'm not sure how to go about adding the dependency. Is there any documentation on this?  

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ibishika

Add a dependency in your core pom of your second site. Something like this:

<dependency>

    <groupId>com.myproject</groupId>

    <artifactId>common-code</artifactId>

    <version>1.0.0</version>

</dependency>

 

The artifactId and groupId should be same as you have defined in your project(first site).

 

Then you can use it in your HTL pretty much same way how you would use when you call it in the same project.

 

May be you can refer this link for more details: https://stackoverflow.com/questions/15383322/how-do-i-add-a-project-as-a-dependency-of-another-project

2 replies

ibishika
ibishikaAccepted solution
Level 4
January 3, 2022

Add a dependency in your core pom of your second site. Something like this:

<dependency>

    <groupId>com.myproject</groupId>

    <artifactId>common-code</artifactId>

    <version>1.0.0</version>

</dependency>

 

The artifactId and groupId should be same as you have defined in your project(first site).

 

Then you can use it in your HTL pretty much same way how you would use when you call it in the same project.

 

May be you can refer this link for more details: https://stackoverflow.com/questions/15383322/how-do-i-add-a-project-as-a-dependency-of-another-project

milind_bachani
Adobe Employee
Adobe Employee
January 5, 2022

hi @nydel09 ,

The solution mentioned my @ibishika is perfect, although when you implement these and do deployments - you need to take care of deployment sequence (deploying common code before dependent code) and also since you are using specific version in POM you need to keep updating it with every release.

This sounds like a minor challenge with only one project dependent on another, however when you have multiple projects interdependent on each other - versioning and sequential deployments are going to be an hassle.

thanks.


Level 3
January 5, 2022

Add a dependency in second site so after module compilation classes get availble for use.