Hybris 新建一个Extension项目

110 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

 Creating a New Extension

Extension templates enable you to create your own extensions that you can then use for specific implementations.

SAP Hybris Commerce comes with an extension generator system called extgen.

Using extgen, you can create new extensions based on extension templates. A number of extension templates are available.

Tip

To add your own template extension to the selection of extgen templates please add the following line to the extensioninfo.xml of your template extension.

Optional: Setting Default Values for New Extensions

You can personalize extgen default behavior by modifying the project.properties file located in <${HYBRIS_BIN_DIR}>/platform/extgen. Extgen then uses your settings as the default to generate the extension.

Modifying the default values is only necessary for advanced settings. Extgen prompts you to provide the basic values during the extension generation process.

Copy an Extension Template Using Extgen

An extension template is a predefined basic extension to be duplicated. The copy serves as a starting point for creating a new extension, typically used for a customer specific implementations.

  1. Open a command prompt.
  2. Navigate to the <HYBRIS_BIN_DIR> /platform directory.
  3. Run the <HYBRIS_BIN_DIR> /platform/setantenv.bat file. Don't close the command prompt as the settings are transient and are lost if the command prompt is closed.
  4. Run ant extgen in <HYBRIS_BIN_DIR>/platform directory. This internally runs ant in the extgen directory.

Extgen prompts you to specify values for the technical aspects of an extension. Extgen comes with default values for all these technical aspects. These default values are defined in the project.properties file in the extgen directory. The default value is displayed in brackets ([ and ]), such as:

Press [Enter] to use the default value [training]

You can simply use the default value by pressing Enter.

Note

Not All Possible Configuration Settings Are Prompted. Extgen only prompts you for the most important values for your extension. To modify some advanced settings such as the extension directory, you need to modify the project.properties file in the extgen directory.

Extgen prompts you to specify:

  • The extension's name.

  • The extension's Java package.

  • The extension template to use.

    For a list of available extension templates compatible with extgen, see section below Available Extension Templates.

After you have provided the prompted values, extgen:

  1. Copies the extension template to a temporary directory.
  2. Modifies the extension template to reflect the specified values.
  3. Copies the new extension from the temporary directory to the directory specified by the extgen.extension.path property in the project.propertiesfile.

After the copy process is completed, the extension is ready to be referenced in the localextensions.xml.

Reference the New Extension in localextensions.xml File

To make sure that an extension is integrated into the build framework, you need to reference the extension in the localextensions.xml file. Please note that by default this file only contains references to folders from which it loads all extensions:

Hence, if you want to add a new extension, myextension, add this line to localextensions.xml:

For details, see Configuring Available Extensions.

For more information, see Build Framework.

Rebuild the SAP Hybris Commerce

  1. Open a command prompt.

  2. Navigate to the <HYBRIS_BIN_DIR>/platform directory.

  3. Make sure that a compliant version is used:

    • On the Windows operating system, call the <HYBRIS_BIN_DIR>/platform/setantenv.bat file. Do not close the command prompt after this call as the settings are transient and would get lost if the command prompt is closed.
    • On the Unix operating system, call the <HYBRIS_BIN_DIR>/platform/setantenv.sh file, such as: . ./setantenv.sh.
  4. Call ant clean all to build the entire Hybris Commerce.

Configure an Extension

An extension is configured by the extensioninfo.xml file. It defines the contained extension modules and list of extensions that the current extension depends on.

To define properties of the extension, use the local.properties file. See also Configuring the Behavior of SAP Hybris Commerce.

For more information, see:

Available Extension Templates

Note

Depending on the packages at your disposal, you may not have access to all extension templates.

Tip

Adding a Custom Template

To add your own template extension to the selection of extgen templates, add the following line to the extensioninfo.xml of your template extension.

Hybris Commerce comes with the following extensions, which you can use as a template for new extensions:

Extension Template

Documentation

yempty

yempty Extension Template

ycockpit

ycockpit Template Extension

yaddon

yaddon Extension

ybackoffice

Structure of the Custom Backoffice Extension

yacceleratorcore

yacceleratorcore Extension

yacceleratorfacades

yacceleratorfacades Extension

yacceleratorstorefront

yacceleratorstorefront Extension

yacceleratorcockpits

yacceleratorcockpits Extension

yacceleratorinitialdata

yacceleratorinitialdata Extension

yacceleratortest

yacceleratortest Extension

ycommercewebservices

ycommercewebservices Extension

yacceleratorordermanagement

yacceleratorordermanagement Extension

yacceleratorfulflmentprocess

yatddtests

ycommercewebservicestest

ycommercewebservicestest Extension

yoccaddon

yoccaddon Extension

ysaporderfulfillment

ysaporderfulfillment Extension

ysapordermgmtb2baddon

ysapordermgmtb2baddon AddOn

ysapproductconfigb2baddon

ysapproductconfigaddon AddOn

yhacext

Adding Functionalities to HAC