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
- <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
- <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.
external-dependencies.xml file we can use for adding dependencies through maven.
add usemaven=”true” in extensioninfo.xml
and use unmanaged-dependencies.txt file to declare jar files not managed via maven
Hi Kari.
Thanks a lot for your detailed explanation on extensions. I have got some queries.
I have added adaptive search(adaptivesearchbackoffice) extension for enabling adaptive search perspective in Hybris Back Office and commented out commercesearchbackoffice to disable it from Hybris Back Office. I have done the build and restarted the server. Even though I have commented out commercesearchbackoffice still I could see “Commerce Search” perspective as well. As per Hybris, it is not recommended to use Commerce Search and Adaptive Search at the same time as it may cause mixed results to occur.
Can you please guide?
In the sample extensioninfo.xml there are many properties like abstratclassprefix, managername,generated….
Could you explain them why we are using them?
When we should use them?
your Posts are really informative. I have started following you and learnt many things in hybris.
I have a question here.
How can I customize the logic of clearing Cache from HAC.
Need to customize code written inside CacheController.class file.
How can i achieve it using a new extension.
Your help will be appreciated.
Hi KB,
I want to know the template name required at the of creating extension which does not create the WEB folder so that we can create jsp in that extension. And what is the use of that extension?
Thanks!
use yempty template
But yempty creates the WEB folder.
Hi,
Your explanation about extension is superb.how to provide core any other module behaviour to the extension.can you write the steps to needed to write in extensioninfo.xml
This blog is very helpful for beginners to know the hybris basics and terminology.
Please provide deep information on some other topics in hybris. Thank you KB
Thank you Vinay. Will do it.
hi,
can anyone tell me which data type is used for image in for data modelling
Hi Ankit,
In Hybris, we are using Media type for image or video or any media in general.
This Media type holds the details of the image like its format,mime type etc and the url of the image.
Images can be kept in any folder or server path and its location can be given to media.
Note:Media item type does not contain the actual image but it contains the path/url where the image resides.
Your posts are very simple and to the point. A must for someone who is noob to Hybris
This will surely bolster my confidence in writing more.
Thanks a lot Rahul !!