The following example shows how to run two separate processes to initialize MATLAB® struct arrays.
Note:
You do not need the MATLAB Runtime installed on the client
side. Return values from the MATLAB Runtime can be automatically
converted using the |
Compile the Java® package by issuing the following command at the MATLAB command prompt:
mcc -W 'java:dataTypesComp,dataTypesClass' createEmptyStruct.mcreateEmptyStruct.m updateField.mupdateField.m -v
Compile the server Java code by issuing the following javac
command.
Ensure there are no spaces between javabuilder.jar;
and directory_containing_pacakage
.
javac -classpath matlabroot\toolbox\javabuilder\jar\javabuilder.jar; directory_containing_pacakage\dataTypesComp.jar DataTypesServer.java
You can find DataTypesServer.java
DataTypesServer.java
in:
matlabroot\toolbox\javabuilder\Examples\RMIExamples \DataTypes\DataTypesDemoJavaApp
Compile the client Java code by issuing the following javac
command.
Ensure there are no spaces between javabuilder.jar;
and directory_containing_pacakage
.
javac -classpath matlabroot\toolbox\javabuilder\jar\javabuilder.jar; directory_containing_pacakage\dataTypesComp.jar DataTypesClient.java
Run the client and server as follows:
Open two command windows.
If running Windows®, ensure that
is
defined on the system path. If running UNIX®, ensure matlabroot
/runtime/arch
LD_LIBRARY_PATH
and DYLD_LIBRARY_PATH
are
set properly.
Run the server by issuing the following java
command.
Ensure there are no spaces between dataTypesComp.jar;
and matlabroot
.
java -classpath .;directory_containing_pacakage\dataTypesComp.jar; matlabroot\toolbox\javabuilder\jar\javabuilder.jar -Djava.rmi.server.codebase= "file:///matlabroot/toolbox/javabuilder/jar/javabuilder.jar file:///directory_containing_pacakage/dataTypesComp.jar" DataTypesServer
Run the client by issuing the following java
command.
Ensure there are no spaces between dataTypesComp.jar;
and matlabroot
.
java -classpath .;directory_containing_pacakage\dataTypesComp.jar; matlabroot\toolbox\javabuilder\jar\javabuilder.jar DataTypesClient
You can find DataTypesClient.java
in:
.matlabroot
\toolbox\javabuilder\Examples\RMIExamples\DataTypes\DataTypesDemoJavaApp
If successful, the following output appears in the Command Window running the server:
Please wait for the server registration notification. Server registered and running successfully!! EVENT 1: Initializing the structure on server and sending it to client: Initialized empty structure: Name: [] Address: [] ################################## EVENT 3: Partially initialized structure as received by server: Name: [] Address: [1x1 struct] Address field as initialized from the client: Street: '3, Apple Hill Drive' City: 'Natick' State: 'MA' Zip: '01760' ################################## EVENT 4: Updating 'Name' field before sending the structure back to the client: Name: 'The MathWorks' Address: [1x1 struct] ##################################
Running the client application!! EVENT 2: Initialized structure as received in client applications: Name: [] Address: [] Updating the 'Address' field to : Street: '3, Apple Hill Drive' City: 'Natick' State: 'MA' Zip: '01760' ################################# EVENT 5: Final structure as received by client: Name: 'The MathWorks' Address: [1x1 struct] Address field: Street: '3, Apple Hill Drive' City: 'Natick' State: 'MA' Zip: '01760' #################################