Making Extensions Accessible
To make an extension available to Data Hub, it has to be in /opt/datahub/extensions/. Once the extension is compiled into a JAR file, copy it into the /opt/datahub/extensions directory. Here we outline some approaches for regular testing while developing an extension.
Using an External Libraries Directory with the Tomcat Server
This approach is suitable in cases when you do not use Maven for development and run Data Hub on a Tomcat server. You can use Tomcat's context.xml file to define an external classpath directory as in the following example:
datahub-webapp.xml
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context antiJARLocking="true"
docBase="{full path to your Hybris installation}/hybris/bin/ext-integration/datahub/web-app/datahub-webapp-x.x.x.x-RCx.war"
reloadable="true" >
<Resources className="org.apache.catalina.webresources.StandardRoot">
<PostResources className="org.apache.catalina.webresources.DirResourceSet"
base="/opt/datahub/config" internalPath="/" webAppMount="/WEB-INF/classes" />
<PostResources className="org.apache.catalina.webresources.DirResourceSet"
base="/opt/datahub/extensions" webAppMount="/WEB-INF/lib" />
</Resources>
</Context>
Place this file into the <TOMCAT_HOME>/conf/Catalina/localhost directory.
For more details about Tomcat context file configuration and deployment refer to Install the Basic Prerequisites or the Tomcat document for The Context Container
.
Data Hub Web Application Overlay
This approach is very convenient for developers using Maven for their builds. The general idea is to set up a Web application project overlaying the datahub-webapp WAR distribution and adding dependencies to your extension(s). The following is a simple example of how the build environment can be set up with Maven. This example demonstrates a common best practice of separating a Maven multimodule project from the project inheritance. In the case where the multimodule build provides the inheritance it can be even simpler. Assume you work for MyCorp and develop a Data Hub extension, which is called myExtension. The project can be organized into the following sub projects, which are stored in this directory's hierarchy:
Project Structure
myextension-modules | +- pom.xml | +- myextension-parent | | | +- pom.xml | +- myextension | | | +- pom.xml | +- datahub-overlay | +- pom.xml
Of course the project/directory names can be different, but these names are referred to in further explanations.
myextension-modules
The following is a simple Maven project for a multimodule build.
myextension-modules/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycorp.datahub</groupId>
<artifactId>myextension-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>myextension-modules</name>
<modules>
<module>myextension-parent</module>
<module>myextension</module>
<module>datahub-overlay</module>
</modules>
</project>
The project builds myextension-parent, myextension, and datahub-overlay project together.
myextension-parent
The following is a parent project for the extension and Data Hub overlay projects. It provides a common version number and common dependencies to be used by its children. Since all its children depend on Data Hub, it is a good idea to define the Data Hub version here:
myextension-parent/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycorp.datahub</groupId>
<artifactId>myextension-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<datahub.version>5.7.0.0</datahub.version>
</properties>
</project>
Note, the version of this project does not have to be the same as the version of the myextension-module. You can change the version of this project any time you change the extension. You can change the version of the myextension-modules project only when you change the multimodule build. For example, when you add or remove modules from the project.
If your company develops multiple Data Hub extensions, it is possible this project exists somewhere else outside of the myextension-modules hierarchy. It may provide common corporate rules for building Data Hub extensions, enforcing quality standards, managing distribution, and so on.
myextension
The following is a project for developing a Data Hub extension. It defines the necessary data modules, perhaps includes custom code to enhance Data Hub, defines Spring beans, and so on. It produces a JAR file to be deployed in Data Hub. The project can be set up manually in a simple structure or can be generated from the Tutorial: Setting Up Your Environment for Custom Extension Development. However the pom.xml for the project may look something like the following:
myextension/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycorp.datahub</groupId>
<artifactId>myextension-parent</artifactId>
<relativePath>../myextension-parent</relativePath>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>myextension</artifactId>
<dependencies>
<dependency>
<groupId>com.hybris.datahub</groupId>
<artifactId>datahub-extension-sdk</artifactId>
<version>${datahub.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
As you can see, this project inherits its version from the parent project and declares a dependency to datahub-extension-sdk.jar, which any extension project must have.
datahub-overlay
The goal of this project is to build a Data Hub web application with your extension being accessible through datahub-webapp.xml. So, you can deploy it to a standalone application server or run it embedded in the IDE. Then you won't have to manually drop the myextension.jar into the WEB-INF/lib directory. Here is how the pom.xml might look:
datahub-overlay/pom.xml
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycorp.datahub</groupId>
<artifactId>myextension-parent</artifactId>
<relativePath>../myextension-parent</relativePath>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>datahub-overlay</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.hybris.datahub</groupId>
<artifactId>datahub-webapp</artifactId>
<version>${datahub.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.mycorp.datahub</groupId>
<artifactId>myextension</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>datahub-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<overlays>
<overlay>
<id>datahub-webapp</id>
</overlay>
</overlays>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/datahub-webapp</path>
<httpsPort>8443</httpsPort>
<keystoreFile>${project.build.directory}/datahub-webapp/WEB-INF/classes/datahub.jks</keystoreFile>
<keystorePass>123456</keystorePass>
</configuration>
</plugin>
</plugins>
</build>
</project>
There are a few points worth mentioning about the previous example:
- This Maven project does not even need its own source directory, the WEB-INF directory, web.xml, and so on, unless you really want to customize them.
- The maven-war-plugin is sufficient for creating an overlay web application. It is a simple configuration, and, if necessary, you can make it as complex as needed. Refer to Maven War Plugin
documentation for more information about configuration options. - The tomcat7-maven-plugin makes it easy to deploy the Data Hub web application to a local standalone Tomcat server or run it embedded in the IDE. To run Tomcat embedded, execute this command from the datahub-overlay directory :
> mvn tomcat7:run-war
For more details about commands and configuration options, refer to Tomcat Maven Plugin
documentation. - The datahub-webapp finalName is used to make the web application respond to the commonly used Data Hub /datahub-webapp context path in the standalone mode. The Tomcat plugin <path> configuration parameter serves the same purpose for the embedded mode. If you
- don't care about it
- want to use "vanilla" Data Hub without your extension next to a Data Hub with your extension
- plan on using Tomcat's datahub-webapp.xml file to deploy the web application
- All dependencies declared in myextension/pom.xml are also included inside the WEB-INF/lib directory.
Managing Data Hub Dependencies
If you do not have access to Data Hub Maven repositories, add Data Hub artifacts manually to your local Maven repository. If this is the case, download Data Hub distribution, and then run these commands:
mvn install:install-file -DgroupId=com.hybris.datahub -DartifactId=datahub-extension-sdk -Dversion=<datahub_version> -Dfile=<path_to_datahub-extension-sdk.jar> mvn install:install-file -DgroupId=com.hybris.datahub -DartifactId=datahub-webapp -Dversion=<datahub_version> -Dpackaging=war -Dfile=<path_to_datahub-webapp.war>
Where <datahub_version> is the version of Data Hub distribution you are using; <path_to_datahub-extension-sdk.jar> is a path to datahub-extension-sdk.jar on your local machine after extracting it from the distribution zip; and <path_to_datahub-webapp.war> is also a path to datahub-webapp.war after extracting it from the distribution zip.