Altova MapForce 2025 Enterprise Edition

This example shows how to create a sample Java library and reference it in a MapForce Function File (.mff). The .mff file can then be imported as a MapForce library. Referencing a Java library in a .mff file is one of the ways to import Java libraries into MapForce. A simpler alternative is to import Java .class files directly. For more information, see Example: Import Custom Java Class.

 

Configuration steps

To reference a C# library in a .mff file, follow the instruction below.

 

Step 1. Create a new project

Create a new Java project in your preferred development environment (for example, Eclipse).

 

Step 2. Add the com.mylib package

Add to the project a new package called com.mylib which consists of a class called Greetings. In the code listing below, notice that the SayHello function has been defined as public static.

 

package com.mylib;
 
public class Greetings {
 
  public static String SayHello ( boolean isMorning ) {
     if( isMorning )
        return "Good Morning!";
     return "Good Day!";
  }
     
}

 

Step 3. Import com.altova.types

Optionally, if your project needs support for special schema types such as date, time, and duration, import the com.altova.types package. To obtain this package, generate Java code from a mapping without custom functions: import com.altova.types.*;.

 

Step 4. Compile your custom library

Compile your custom library to a class file and add it to the Java classpath.

 

Step 5. Create .mff and reference your Java library

Using an XML editor, create a new .mff file and validate it against the following schema: C:\Program Files\MapForceLibraries\mff.xsd. Make sure that all references under implementation language="java" point to the correct Java members created previously. Also, the line function name="SayHello" must refer to the function name exactly as it was defined in Java. For more detail, see Configure .mff File.

 

<?xml version="1.0" encoding="UTF-8"?>
<mapping version="9" library="custom" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mff.xsd">
  <implementations>
     <implementation language="java">
        <setting name="package" value="com.mylib"/>
        <setting name="class" value="Greetings"/>
     </implementation>
  </implementations>
  <group name="greetings">
     <component name="sayhello">
        <sources>
           <datapoint name="ismorning" type="xs:boolean"/>
        </sources>
        <targets>
           <datapoint name="result" type="xs:string"/>
        </targets>
        <implementations>
           <implementation language="java">
              <function name="SayHello"/>
           </implementation>
        </implementations>
        <description>
           <short>result = sayhello(ismorning)</short>
           <long>Returns "Good morning" or "Good day", depending on the input parameter.</long>
        </description>
     </component>
  </group>
</mapping>

 

Step 6. Import .mff as a library

Now that your custom library is referenced in the .mff file, you can import the .mff file into MapForce as a library. For more information, see Import .mff Libraries.

 

© 2018-2024 Altova GmbH