MATLAB Production Server Java Client Basics
Java® client library lets you evaluate MATLAB® functions deployed on remote servers using native Java data.
mps_client.jar Client Library
There are several options to obtain the
library based on your project set up:
In a MATLAB Production Server™ installation,
mps_client.jaris located in
The library is available for download at MATLAB Production Server Client Libraries. Select your release to download the folder, then unzip it.
mps_client.jaris located in
The library is also hosted in a Maven™ repository at https://mvnrepository.com/artifact/com.mathworks.prodserver/mps_java_client. To use the jar in your Maven project, include the following coordinates in the
<!-- https://mvnrepository.com/artifact/com.mathworks.prodserver/mps_java_client --> <dependency> <groupId>com.mathworks.prodserver</groupId> <artifactId>mps_java_client</artifactId> <version>release_number</version> </dependency>
Configure your development environment to use
mps_client.jar by adding it to your Java class path.
Choose Workflow for Client-Server Communication
The Java client API offers two workflows for client-server communication:
This workflow uses the
MWHttpClient class and hides the
implementation details of request creation and data serialization when evaluating
MATLAB functions deployed on servers. Based on your requirements, your client
can use either a static proxy or dynamic proxy to evaluate deployed MATLAB functions.
A static proxy uses an object implementing an interface that mirrors the deployed MATLAB functions. You provide the interface for the static proxy. This is a type-safe API that enforces passing the proper data types to the function at compile time. For details, see Static Proxy Interface Guidelines.
A dynamic proxy creates server requests based on the MATLAB function name provided to the
invoke()method. You pass the function name as a parameter to the proxy along with the function arguments. You provide the function name, the number of output arguments, and all of the input arguments required to evaluate the functions. Doing so defers type checking until runtime. For more information, see Invoke MATLAB Functions Dynamically.
Following is an outline of Java code to instantiate a proxy to a MATLAB Production Server instance and call the MATLAB functions.
MWClientobject for communicating with the service hosted by a MATLAB Production Server instance.
Create MATLAB data structures to hold the data passed between the client and server.
Invoke MATLAB functions.
Free system resources using the
closemethod of the
For a complete example, see Create MATLAB Production Server Java Client Using MWHttpClient Class.
Use RESTful API and protobuf
This workflow uses the MATLAB Production Server RESTful API for MATLAB Function Execution for request creation and protocol buffers (protobuf) for data serialization. Protocol buffers are a language-neutral and platform-neutral method of serializing structured data.
To use protobuf when making a request to the server, set the
Content-Type header to
in the client code. The Java client library provides helper classes to internally create protobuf messages
based on a proto format and returns the corresponding byte array. Use this byte array in the
HTTP request body. The Java client library provides methods and classes to deserialize the protobuf