Main Content

Package MATLAB App Using Web App Compiler App

Supported platforms: Windows®, Linux®, Mac

This example shows how to use the Web App Compiler app to package a MATLAB® app into a web app.

Before R2025a: Create a web app using the previous version of the Web App Compiler app as shown in Create Web App (R2024b).

Create MATLAB App Using App Designer

Before you can package and then deploy a web app, you need to create an app using MATLAB App Designer. For more information, see Create and Run a Simple App Using App Designer.

For this example, create a web app using a MATLAB app that displays blood pressure data. To open the app in App Designer, open the App Designer Start Page and click Show examples in the Apps section. Then, select Respond to User Selections.

The software creates a folder named BloodPressureAppExample that contains the files for the example. The files required for this example are the MATLAB file PatientsDisplay.mlapp and the data file patients.mat.

MATLAB app titled Patients Display shows a scatter plot of systolic blood pressure measured against weight for male patients

Create Project and Compiler Task

Create a compiler task for your web app using the Web App 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 Web App Compiler.

Application Deployment section of the Apps gallery

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

After you open the app, the Create Compiler Task dialog box prompts you to add a 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 BloodPressureAppExample in the BloodPressureAppExample 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 WebAppArchive1 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 web app to customize the building process. For instance, you can obfuscate the MATLAB code or modify the app details.

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

Add the MATLAB app to the web app. All files must be located in the project root folder to be added to the project. For this example, in the Main File section of the compiler task, click Add File and select PatientsDisplay.mlapp. In the Project panel, the files now have the labels Design and Main Function.

In the Archive Info section, replace the string MyWebAppArchive with the name for your web app, BloodPressureExample.

Package Web App

To view code that contains instructions on building and packaging your component, click the arrow next to Export Build Script and select Show Code. On the right, a window displays a deployment script with the compiler.build.webAppArchive and compiler.build.WebAppArchiveOptions functions that correspond 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.

Two buttons labeled Export Build Script and Package

To create the web app, click Package.

The compiler generates files in the <compiler_task_name>/output folder in your project folder. To choose a different output location for the generated files, update the path in the Output Location section.

Deploy and Run Web App

Navigate to the project folder generated by MATLAB Compiler™ during the packaging process.

Copy the web app archive file BloodPressureExample.ctf to the app folder configured by the server. This table lists the default folder locations.

Operating SystemApps Folder Location

Windows

%ProgramData%\MathWorks\webapps\R2025a\apps

Linux

/local/MathWorks/webapps/R2025a/apps

macOS

/Library/Application Support/MathWorks/webapps/R2025a/apps

You can also open the apps folder by clicking the Open App Folder button in the server application in the development version of MATLAB Web App Server™. For more information, see Start the Server Application.

Alternatively, you can upload the app directly to the server if you are using the MATLAB Web App Server product. To upload the app, navigate to the web apps home page and select Manage Apps > Upload App. This functionality requires the activation of authentication and role-based access controls. For more information, see Deploy Web App.

You can obtain the URL to the home page by clicking Open Home Page in the server application. The format of the home page URL is:

http://webAppServer:PortNumber/webapps/home/index.html

Open the web apps home page in your web browser. You see a tile displaying the patient display web app. Your web app is now deployed.

See Also

|

Topics