Create MATLAB Production Server Archive Using Production Server Archive Compiler App - MATLAB & Simulink (original) (raw)

Supported platforms: Windows®, Linux®, Mac

This example shows how to use the Production Server Archive Compiler app to package a MATLAB® function into a MATLAB Production Server™ archive. You can deploy the archive to MATLAB Production Server.

Before R2025a: See Create Deployable Archive for MATLAB Production Server (R2024b).

Create MATLAB Function

Write a MATLAB program that you want to deploy. For information on writing MATLAB code for MATLAB Production Server, see MATLAB Coding Guidelines.

For this example, create a function named addmatrix.m.

function a = addmatrix(a1, a2) a = a1 + a2;

At the MATLAB command prompt, enter addmatrix([1 4 7; 2 5 8; 3 6 9], [1 4 7; 2 5 8; 3 6 9]).

The output is a 3-by-3 matrix.

Create Project and Compiler Task

Create a compiler task for your function using the Production Server Archive Compiler. Compiler tasks allow you to compile files in a project for a specific deployment target.

To open the app, on the Apps tab, expand theApps gallery. In theApplication Deployment section, click Production Server Archive Compiler.

Application Deployment section of the Apps gallery

You can also open the app using the productionServerArchiveCompiler function at the MATLAB Command Window.

After you open the app, the Create Compiler Task dialog box prompts you to add a compiler task to a new or an existing MATLAB project. For this example, select Start a new project and create a compiler task and create a new project namedMatrixProject in your working folder. For more information on creating and using MATLAB projects, see Create Projects.

Create compiler task dialog box with the text 'To deploy your MATLAB code, you need a MATLAB project to organize code and a compiler task to handle deployment.' The option 'Start a new project and create a compiler task' is selected.

A new compiler task named ProductionServerArchive1 opens in the Editor. You can compile code for other deployment targets by opening the Compiler Task Manager or going to the Manage Tasks tab and creating a new compiler task.

Specify Build Options

You can specify options for the MATLAB Production Server archive before packaging to customize the building and packaging process. For instance, you can obfuscate the MATLAB code or add a function signature file. For information on function signatures, see MATLAB Function Signatures in JSON (MATLAB Production Server).

For this example, in the Exported Functions section of the compiler task, click Add Exported Function and selectaddmatrix.m. In the Project panel, the file now has the labelsDesign and Exported Function File.

Exported file section of the compiler task with no file selected and a button labeled Add Exported Function

In the Package Info section, replace the stringMyProductionServerArchive with the name for your MATLAB Production Server package, AddMatrixArchive.

View Code and Package MATLAB Production Server Archive

To view code that contains instructions on building and packaging your component, click the arrow next to the Export Build Script button and selectShow Code. On the right, a window opens that displays a deployment script with the compiler.build.productionServerArchive function that corresponds to your build options.

You can convert this code to a MATLAB script file by clicking the Export Build Script button. Running the generated build script is equivalent to clicking thePackage button.

Three buttons labeled Test Client, Export Build Script, and Package

To create the MATLAB Production Server archive, click Package.

The compiler generates files in the_`<compilertaskname>`_/output folder in your project folder. To choose a different output location for the generated files, update the paths in the Output Location section.

Test and Deploy Archive

After creating the deployable archive, you write source code for a client application that calls the MATLAB function in the archive using HTTP or HTTPS requests. To create a client for this example using the MWHttpClient class from the Java® client API, see Create MATLAB Production Server Java Client Using MWHttpClient Class (MATLAB Production Server).

You can test your RESTful API or Java client using the development version of MATLAB Production Server. MATLAB Compiler SDK™ includes the development version of MATLAB Production Server for testing and debugging application code and Excel® add-ins before deploying them to web applications and enterprise systems. To test your client, see Test Client Data Integration Against MATLAB.

To deploy your archive, see Deploy Archive to MATLAB Production Server (MATLAB Production Server).

See Also

Production Server Archive Compiler | compiler.build.productionServerArchive

Topics