Extension Basic Details


Lets understand the basic details of Extension


Extension in Hybris is very similar to Project in Java.

We know that Project basically contains the business logic and some configuration files(XML,properties files).

Similarly Extension in Hybris contains the same and some additional files but it’s called Extension instead of Project in Hybris.

Every extension will have one important file called extensioninfo.xml file

This file as the name suggests contains the information about the extension

Basically it contains the following details


Extension Name

Extension Module like Core,Web or HMC module

Dependencies on other extension

Extension Name


Each extension should specify their name in the extensioninfo.xml

The name we specify in this file is considered as the extension name by the hybris framework.

So referring to the extension anywhere will use this name only.

We specify extension name in localextensions.xml and extensioninfo.xml file of other extensions where there is a dependency.

In all these places, we should use the same name as we specified in the extension’s extensioninfo.xml file.

Extension Module


Every extension includes one or more extension modules where each module adds some functionality to the extension.

There are different extension modules available in Hybris and they are

Core Module

Web module

HMC module

Core Module:


Core module of an extension provides some basic features like defining the item types using extension_name-items.xml file located in the
extension’s resources directory and also localization files inside resources/localization directory and few others.

Web Module:


This module enables the extension to access through the Web Url, to access it over the web, we must use the URL like below

http://host:port/extension-name

example

http://localhost:9001/MyStorefront

Where MyStorefront is the name of the extension.

We can also provide web root instead of extension name to access it.

Generally in Hybris Storefront extension is accessed over web because that extension contains the starting page of the site which is Home page,

And storefront extension uses Web module to achieve the same.

HMC Module:


An extension can use this module to enable the HMC configuration of an extension.

All the HMC related files should be inside hmc directory of an extension which includes hmc.xml file ,jsp files ,source files and localization files related to hmc.

Dependencies on other extension


If an extension is dependent on other extensions then it should define those dependencies using requires-extenion tag.

If extension A is dependent on extension B and C then extensioninfo.xml file of extension A should have below 2 tags

1
2
<requires-extenion name=”B”>
<requires-extenion name=”C”>
<requires-extenion name=”B”>
<requires-extenion name=”C”>

Whereas B and C are the names of the extension B and C defined in their extensioninfo.xml file.

There are many predefined extensions available in Hybris suite.

Why should we go for creating new extension?

We are not supposed to modify any of the existing extension in Hybris.

We should always create new extension to define the custom logic in Hybris.

Even if there is a single line of code change, we should not do that in the existing extension.

Sample trainingcore extension’s extensioninfo.xml file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<extension abstractclassprefix="Generated" classprefix="TrainingCore" managername="TrainingCoreManager" managersuperclass="de.hybris.platform.jalo.extension.Extension" name="trainingcore">
        
        <requires-extension name="acceleratorservices"/>
        <requires-extension name="acceleratorcms"/>
        <requires-extension name="trainingfulfilmentprocess"/>
        <requires-extension name="hmc"/>
 
        <coremodule generated="true" manager="org.training.core.jalo.TrainingCoreManager"    
                                                      packageroot="org.training.core"/>
 
        <hmcmodule extensionclassname="org.training.core.hmc.TrainingCoreHMCExtension"/>
 
        <meta key="backoffice-module" value="true"/>
    
       </extension>
 
</extensioninfo>
<extension abstractclassprefix="Generated" classprefix="TrainingCore" managername="TrainingCoreManager" managersuperclass="de.hybris.platform.jalo.extension.Extension" name="trainingcore">
		
		<requires-extension name="acceleratorservices"/>
		<requires-extension name="acceleratorcms"/>
		<requires-extension name="trainingfulfilmentprocess"/>
		<requires-extension name="hmc"/>

		<coremodule generated="true" manager="org.training.core.jalo.TrainingCoreManager"    
                                                      packageroot="org.training.core"/>

		<hmcmodule extensionclassname="org.training.core.hmc.TrainingCoreHMCExtension"/>

		<meta key="backoffice-module" value="true"/>
	
       </extension>

</extensioninfo>

Here the extension name is defined as trainingcore

It has defined core module and HMC module

And it also has dependency on some of the extensions specified using requires-extension tag.

Adding external jars to the extension


Sometimes it’s required to add the external jar files to an extension.

We can add that in the below path

/lib directory for core extension module
/web/webroot/WEB-INF/lib directory for web extension module

Note:

Each extension will also have extensioninfo.xsd file which is used to validate the extensioninfo.xml file during the build phase.

About the Author

Karibasappa G C (KB)
Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on