MATLAB: How to test a component created with MATLAB Builder JA Version 2.0.3 (R2009a) within MATLAB without using a driver application

exampleMATLAB Compiler SDKrunsample

I have created a component using MATLAB Builder JA. I would like to run this component within MATLAB in order to test it without having to create a separate Java file (driver application) that instantiates the component and runs it.

Best Answer

This change has been incorporated into the documentation in Release 2010a (R2010a). For previous releases, read below for any additional information:
The following line of code will directly run a MATLAB Builder JA component that was created using the deploytool, for which the project name is "Test" and the class name is "TestClass" (note that the name of the MATLAB file included in the class is not taken into account):
- Windows:
(Note that the commands below should be executed in one line)
!java -classpath $matlabroot\toolbox\javabuilder\jar\javabuilder.jar;.\Test\distrib\Test.jar Test.TestClass
... where $MATLABROOT is the MATLAB installation directory.
Similarly, the above project can be executed on a machine that only has the MATLAB Compiler Runtime (MCR) installed:
java -classpath $matlabroot\toolbox\javabuilder\jar\javabuilder.jar;.\Test\distrib\Test.jar -Djava.library.path=$mcrroot\runtime\$ARCH Test.TestClass
... where $mcrroot is the MCR installation directory and $ARCH is the operating system and processor type of the local machine (e. g. win32).
- Linux:
(Note that the commands below should also be executed in one line)
!java -classpath $matlabroot/toolbox/javabuilder/jar/javabuilder.jar:.\Test\distrib\Test.jar Test.TestClass
Note that a colon (:) is used, instead of a semi-colon (;), to separate the class paths.
MCR:
java -classpath $matlabroot/toolbox/javabuilder/jar/javabuilder.jar:.\Test\distrib\Test.jar -Djava.library.path=$mcrroot/runtime/$ARCH Test.TestClass