Main Content

MATLAB Production Server Java Client Basics

The Java® client library provides an API that lets you evaluate MATLAB® functions deployed on remote servers by using native Java data.

Obtain and Configure Client Library

Before you can use the client library API, you need to obtain the mps_client.jar file containing the library, and then configure your development environment to access this file by adding it to your Java class path.

You can obtain the mps_client.jar client library from one of these locations:

  • In a MATLAB Production Server™ installation, mps_client.jar is located in $MPS_INSTALL/client/java.

  • On in MATLAB Production Server Client Libraries, select your release to download and unzip the client library archive. The mps_client.jar file is located in the /java folder.

  • In the Maven™ repository at To use the jar in your Maven project, include the following coordinates in the pom.xml file:

    <!-- -->

Choose Workflow for Client-Server Communication

The API in the Java client library offers two workflows for client-server communication, one that uses a proxy-based process and another that is language- and platform-neutral.

Proxy-Based Workflow Using MWHttpClient Class

This workflow uses the MWHttpClient class and hides the implementation details of request creation and data serialization when you evaluate MATLAB functions deployed on servers. Based on your requirements, your client can use either a static proxy or dynamic proxy to evaluate the 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 interface is type-safe and 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 that you provide 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. This process defers type checking until run time. For more information, see Invoke MATLAB Functions Dynamically.

To instantiate a proxy to a MATLAB Production Server instance and call the MATLAB functions, follow these basic steps.

  1. Create an MWClient object for communicating with the service hosted by a MATLAB Production Server instance.

  2. Create MATLAB data structures to hold the data passed between the client and server.

  3. Invoke MATLAB functions.

  4. Free system resources using the close method of the MWClient object.

For a complete example, see Create MATLAB Production Server Java Client Using MWHttpClient Class.

Language- and Platform-Neutral Workflow Using 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 HTTP Content-Type header to application/x-google-protobuf 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 responses.

For examples, see Asynchronous RESTful Requests Using Protocol Buffers in the Java Client and Synchronous RESTful Requests Using Protocol Buffers in the Java Client.

Related Topics