Using a Custom JAR in a mapping

In this example we will use the custom class created in the Custom JAR in the previous example.

  1. Start the mapper.
  2. Open the Mapping Developing perspective.

    The project MyCustomJAR is a Java project, and not a mapping project, it will not be shown in the Mapping Explorer view. If you want to work in this project again, you must switch to the Java perspective.

  3. Create a new mapping, or use an existing mapping.
  4. In the Mapping Explorer view, expand the mapping view to show the Library node.
  5. Right-click the Library node, select Import JARs.
  6. Browse to your Custom JAR file (MyCustomJAR.jar) and select it.

    You can import more Custom JAR files, if needed.

  7. Click Open.

    The Custom JAR file is created under the Library node. A checksum is added to the Custom JAR file name.

  8. Create a Java function in the mapping, if no Java function already exist.

    Double-click the Java function to edit the Java code, or right-click > Edit Java Code. You must open a new Java editor.

    You can now use your custom Java class in the Java code, just as any other standard Java class, for example String.

    To use your custom Java class, follow these guidelines:

    • Press Ctrl-space to use the Content Assist command for using your custom class in the Java editor.

    • If you specify the package name "cust", the class name "MyCustomClass" is automatically suggested.

    • If you have included the Java source code in the Custom JAR, the custom class Javadoc will also be shown in the Java editor.

      See Editing Java and Boolean functions.

      Note: Do not forget to enter the package for all references to your custom class.

      This Java code will convert the contents of the string s to camel caps:

      s = cust.MyCustomClass.toCamelCaps(s);
      
      Note: The Java editor in Eclipse uses a Java build path. This build path is set dynamically by the mapper when you open the Java editor by editing the Java code for a Java function. If the current mapping uses one or several Custom JARs, these are added to the project’s Java build path when the Java editor is opened. If you have several mappings in the mapping project, using different Custom JARs, the correct build path is not set until you open a new Java editor for a mapping. If you have a Java editor open for another mapping, using other Custom JARs, and you switch to the already opened Java editor, the build path will be wrong for that mapping, and invalid errors for the Java code may be shown in the editor. In that case, close the Java editor and edit the Java code again to get the correct build path.