This example shows how to create a Java® package using a MATLAB® function. You can then pass the generated package to the developer, who is responsible for integrating it into an application.
To compile a Java package from MATLAB code:
In MATLAB, examine the MATLAB code that want to deploy as a shared library.
Open the Library Compiler.
On the toolstrip, select the Apps tab.
Click the arrow at the far right of the tab to open the apps gallery.
Click Library Compiler.
In the Application Type section of the toolstrip, select Java Package from the list.
Specify the MATLAB functions you want to deploy.
In the Exported Functions section of the toolstrip, click the plus button.
In the file explorer that opens, locate and select the makesqr.m file.
makesqr.m is located in matlabroot\toolbox\javabuilder\Examples\MagicSqaureExample\MagicDemoComp.
Click Open to select the file, and close the file explorer.
makesqr.m is added to the list of exported files and a minus button appears under the plus button. In addition, makesqr is set as:
the library name
the package name
Verify that the function defined in makesqr.m is mapped into Class1.
In the Packaging Options section of the toolstrip, verify that the Runtime downloaded from web check box is selected.
Note: If the Packaging Options section of the toolstrip is collapsed, you can expand it by clicking the down arrow.
This option creates an application installer that automatically downloads the MATLAB runtime and installs it along with the deployed package.
Explore the main body of the MATLAB Compiler project window.
The project window is divided into the following areas:
Application Information — Editable information about the deployed application. This information is used by the generated installer to populate the installed application's metadata. See Customize the Installer.
Class mapper — Description of how the MATLAB functions are mapped to Java classes.
Additional Installer Options — Default installation path for the generated installer. See Customize the Installer.
Files required for your application — Additional files required by the generated application. These files will be included in the generated application installer. See Manage Required Files in a Compiler Project.
Files installed with your application — Files that are installed with your application. These files include:
Select the Open output folder when process completes check box.
Verify that the generated output contains:
for_redistribution — A folder containing the installer to distribute the package
for_testing — A folder containing the raw generated files to create the installer
for_redistribution_files_only — A folder containing only the files needed to redistribute the package
PackagingLog.txt — A log file generated by the compiler
Click Close on the Package window.
To follow up on this example:
Try running the function from the command line as follows:
Open a system command prompt.
Navigate to the for_testing folder of the generated deployment project.
Enter the following command:
java -classpath "matlabroot\toolbox\javabuilder\jar\javabuilder.jar";makesqr.jar makesqr.Class1 5
matlabroot is the full path to your MATLAB installation.
Try creating a package that consists of more than one function.