Documentation

Map Functions to Java Class Methods

Map Functions to Java Classes with the Library Compiler App

The Library Compiler app presents a visual class mapper for mapping MATLAB® functions to Java® classes. The class mapper is located between the Application Information and the Additional Installer Options sections of the app.

The Namespace field at the top of the class browser specifies the name of the application into which the generated classes are placed. By default, the name of the first listed MATLAB file is used as the application name. You can change the application name to fit the naming conventions used by your organization.

The table used to match functions to classes is below the application name. The Class Name column specifies the name of the generated Java class. The Method Name column specifies the list of MATLAB functions that are mapped into methods of the generated class.

Add a New Class to a Java Application

To add a class to a Java application:

  1. Click Add Class.

  2. Rename the class as described in Rename a Java Class.

  3. Add one or more methods to the class as described in Add a Method to a Java Class.

Rename a Java Class

To rename a Java class:

  1. Select the name of the class to be renamed.

  2. Open the context menu.

  3. Select Rename.

  4. Enter the new class name.

    The class name must follow the Java naming guidelines. It cannot contain any special characters, dots, or spaces.

Delete a Class from a JavaApplication

To delete a class from a Java application:

  1. Select the name of the class to be deleted.

  2. Open the context menu.

  3. Select Delete.

Add a Method to a Java Class

To add a method to a Java class:

  1. In the Method Name column of the row for the class to which the method is being added, click the plus button.

  2. Select the name of the function to add.

Delete a Method from a Java Class

To delete a method from a Java class:

  1. Select the name of the function to be deleted.

  2. Open the context menu.

  3. Select Delete.

Tip

You can also delete the method using the Delete key.

Map Functions to Java Classes with mcc

When using mcc to generate Java applications, you map your MATLAB functions into Java classes based on the list into which they are placed on the command line. Class groupings are specified by adding one or more class{className:mfilename...} entries to the command line. All of the files not included in a class grouping are added to the class specified by the -W java:packageName,className flag.

For example, mcc —W java:myPackage,MyClass fun1.m fun2.m fun3.m generates a Java application myPackage that contains a single class MyClass. MyClass has three methods: fun1, fun2, and fun3.

However, mcc —W java:myPackage,MyClass fun1.m fun2.m class{MyOtherClass:fun3.m} generates a Java application myPackage that contains two classes: MyClass and MyOtherClass. MyClass has two methods: fun1 and fun2. MyOtherClass has one method fun3.