Create MATLAB Production Server Archive Using Production Server Archive Compiler App
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.
2 8 14 4 10 16 6 12 18
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 the Apps gallery. In the Application Deployment section, click Production Server Archive Compiler.
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 named
MatrixProject
in your working folder. For more information on creating and using MATLAB projects, see Create Projects.
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 select
addmatrix.m
. In the Project panel, the file now has the labels
Design
and Exported Function File
.
In the Package Info section, replace the string
MyProductionServerArchive
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 select
Show 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 the Package button.
To create the MATLAB Production Server archive, click Package.
The compiler generates files in the
folder
in your project folder. To choose a different output location for the generated files,
update the paths in the Output Location section.<compiler_task_name>
/output
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
- MATLAB Coding Guidelines
- Create MATLAB Production Server Java Client Using MWHttpClient Class (MATLAB Production Server)
- Create a C# Client (MATLAB Production Server)
- Create a Python Client (MATLAB Production Server)
- Create a C++ Client (MATLAB Production Server)
- Test Client Data Integration Against MATLAB
- Deploy Archive to MATLAB Production Server (MATLAB Production Server)