Example: Import Custom Java Class
This example shows how to import a custom Java .class file into MapForce.
Note: | Java SE 8 Runtime Environment or later is required to complete this example. |
Java .class import
To add a Java .class file as a MapForce library, take the following steps:
1.Click the Add/Remove Libraries button at the bottom of the Libraries window. The Manage Libraries window opens (see screenshot below).
2.To import functions as a local library (in the scope of the current document only), click Add under the current mapping name. To import functions as a global library (at program level), click Add next to Global Library Imports. When you import a library locally, you can set the path of the library file to be relative to the mapping file. With globally imported libraries, the path of the imported library is always absolute.
3.Search for the following file: <Documents>\Altova\MapForce2025\MapForceExamples\Java\Format\Format.class. A message appears informing you that a new library has been added. The imported library is now visible in the Libraries window (see screenshot below).
If you do not see the newly imported library in the Libraries window, make sure that the transformation language is set to Java. To add the function to the mapping, drag it from the Libraries window into the mapping area. For details, see Add a Function to the Mapping.
Mapping output
To preview the mapping output in MapForce, take the following steps:
1.Open the following mapping: <Documents>\Altova\MapForce2025\MapForceExamples\Java\FormatNumber.mfd. This is a complete mapping that already imports the Java .class library mentioned above.
2.Click the Output button to see the result of the mapping (see screenshot below).
Mapping in Java
To run the mapping in Java, follow the instructions below:
1.Click Generate Code In | Java in the File menu.
2.Select a target directory where the code should be generated and click OK.
3.Import the generated libraries into your Java project and build the Java application. For more information, see Example: Generate and Run Java Code.