A custom Java function (or a set of custom Java functions) may be packaged into a
*.jar file, and made available for use in other projects by your Maven repository.
First, modify the
pom.xml of the project which holds the custom Java function code. In the
pom.xml, replace..
<packaging>ep-eventflow-fragment</packaging>
..with:
<packaging>jar</packaging>
To the same pom.xml, also add the following:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestSections>
<manifestSection>
<name>com/tibco/ep/sample/Hypotenuse.class</name>
<manifestEntries>
<StreamBase-Adapter>False</StreamBase-Adapter>
</manifestEntries>
</manifestSection>
<manifestSection>
<name>com/tibco/ep/sample/VarArgs.class</name>
<manifestEntries>
<StreamBase-Adapter>False</StreamBase-Adapter>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin>
</plugins>
</build>
..where the
<manifestSection> provides the full class name for the custom Java function(s). Check the maven-jar-plugin plugin
<version> value and change it to match your environment. The above example works for the '
Hypotenuse' and '
VarArgs' Java code from the "
custom Java simple function" sample (under
$STREAMBASE_HOME/sample/custom-java-function/).
Next, right-click on the root project folder and select
Maven > Update Project, and update the project.
Next, perform a Maven clean/install. From a StreamBase command prompt (starting in the project root folder), run..
mvn clean install -DskipTests
This will install your custom functions jar to your Maven repository.
Now, in another project where you want to use these functions, simply add this
*.jar as a dependency in the
pom.xml. For example:
<dependency>
<groupId>com.tibco.ep.sample</groupId>
<artifactId>sample_custom-java-function</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Finally, create a StreamBase engine HOCON configuration to reference the custom functions using the
CustomFunctionGroup:
configuration = {
CustomFunctionGroup = {
customFunctions = {
hypotenuse = {
type = "simple"
methodName = "calculate"
className = "com.tibco.ep.sample.Hypotenuse"
autoArguments = true
}
calchyp = {
type = "simple"
methodName = "calculate"
className = "com.tibco.ep.sample.Hypotenuse"
autoArguments = true
}
hypot = {
type = "simple"
methodName = "hypot"
className = "java.lang.Math"
autoArguments = true
}
isIn = {
type = "simple"
methodName = "isIn"
className = "com.tibco.ep.sample.VarArgs"
autoArguments = true
}
sumAll = {
type = "simple"
methodName = "sumAll"
className = "com.tibco.ep.sample.VarArgs"
autoArguments = true
}
mx = {
type = "simple"
methodName = "max"
className = "java.lang.Math"
argumentTypes = [
{ type = "double" }
{ type = "double" }
]
returnType = { type = "double" }
}
}
}
}
These functions will now be available for use by your project.