Main Content

compiler.build.webAppArchive

Create an archive for deployment to MATLAB Web App Server

Description

example

compiler.build.webAppArchive(AppFile) creates a web app archive using a MATLAB® app specified by AppFile.

example

compiler.build.webAppArchive(AppFile,Name,Value) creates a web app archive with options specified using one or more name-value arguments. Options include the archive name, additional files to include, and the output directory.

example

compiler.build.webAppArchive(opts) creates a web app archive with options specified using a compiler.build.WebAppArchiveOptions object opts. You cannot specify any other options using name-value arguments.

results = compiler.build.webAppArchive(___) returns build information as a compiler.build.Results object using any of the argument combinations in previous syntaxes. The build information consists of the build type, the path to the compiled archive, and build options.

Examples

collapse all

Create a web app archive from a MATLAB app named Mortgage.mlapp.

For this example, compile using the file Mortgage.mlapp located in matlabroot\examples\matlab\main.

appFile = fullfile(matlabroot,'examples','matlab','main','Mortgage.mlapp');

Build a web app archive using the compiler.build.webAppArchive command.

compiler.build.webAppArchive(appFile);

The build function generates the following files within a folder named MortgagewebAppArchive in your current working directory:

  • Mortgage.ctf — Component technology file that contains the deployable archive.

  • mccExcludedFiles.log — Log file that contains a list of any toolbox functions that were not included in the web app. For more information on non-supported functions, see MATLAB Compiler Limitations.

  • requiredMCRProducts.txt — Text file that contains product IDs of products required by MATLAB Runtime to run the web app.

  • unresolvedSymbols.txt — Text file that contains information on unresolved symbols.

For information on deploying web apps, see Deploy Web App.

Create a web app archive and customize it using name-value arguments.

For this example, compile using the app Mortgage.mlapp. Use name-value arguments to specify the archive name and output directory, and display progress information during the build process.

compiler.build.webAppArchive('Mortgage.mlapp',...
    'ArchiveName','MyWebApp',...
    'OutputDir','D:\Documents\MATLAB\work\WebApps',...
    'Verbose','on')

The function generates the following files within a folder named WebApps in your current working directory:

  • Mortgage.ctf

  • mccExcludedFiles.log

  • requiredMCRProducts.txt

  • unresolvedSymbols.txt

Create multiple web app archives using a compiler.build.WebAppArchiveOptions object.

Create a WebAppArchiveOptions object using the file example1.mlapp. Use name-value arguments to specify a common output directory, include a MAT-file containing workspace variables, and disable automatic detection of data files.

opts = compiler.build.WebAppArchiveOptions('example1.mlapp',...
    'AdditionalFiles','myvars.mat',...    
    'OutputDir','D:\Documents\MATLAB\work\WebAppBatch',...
    'AutoDetectDataFiles','off',...)
opts = 

  WebAppArchiveOptions with properties:

            ArchiveName: 'example1'
                AppFile: 'D:\Documents\MATLAB\work\example1.mlapp'
        AdditionalFiles: {'D:\Documents\MATLAB\work\myvars.mat'}
    AutoDetectDataFiles: off
              OutputDir: 'D:\Documents\MATLAB\work\WebAppBatch'
                Verbose: off

Build the web app archive using the WebAppArchiveOptions object.

compiler.build.webAppArchive(opts);

To compile using the file example2.mlapp with the same options, use dot notation to modify the AppFile of the existing WebAppArchiveOptions object before running the build function again.

opts.AppFile = 'example2.m';

By modifying the AppFile argument and recompiling, you can compile multiple archives using the same options object.

Create a web app archive and save information about the build type, archive file, and build options to a compiler.build.Results object.

Compile using the file Mortgage.mlapp located in matlabroot\examples\matlab\main.

results = compiler.build.webAppArchive('Mortgage.mlapp')
results = 

  Results with properties:

    BuildType: 'webAppArchive'
        Files: {'D:\Documents\MATLAB\work\MortgagewebAppArchive\Mortgage.ctf'}
      Options: [1×1 compiler.build.WebAppArchiveOptions]

The Files property contains the path to the deployable archive file Mortgage.ctf.

Input Arguments

collapse all

Path to the main file, specified as a row character vector or a string scalar. The file must be a MATLAB app with the .mlapp extension. The path can be relative to the current working directory or absolute.

Example: 'mywebapp.mlapp'

Data Types: char | string

Web app build options, specified as a compiler.build.WebAppArchiveOptions object.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Verbose','on'

Additional files to include in the web app archive, specified as a character vector, a string scalar, a string array, or a cell array of character vectors. File paths can be relative to the current working directory or absolute.

Example: 'AdditionalFiles',["myvars.mat","myfunc.m"]

Data Types: char | string | cell

Name of the web app archive, specified as a character vector or a string scalar. The default value is the file name of AppFile.

Example: 'ArchiveName','MyWebApp'

Data Types: char | string

Flag to automatically include data files, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • If you set this property to 'on', then data files that you provide as inputs to certain functions (such as load and fopen) are automatically included in the web app archive.

  • If you set this property to 'off', then you must add data files to the archive using the AdditionalFiles property.

Example: 'AutoDetectDataFiles','Off'

Data Types: logical

Path to the output directory where the build files are saved, specified as a character vector or a string scalar. The path can be relative to the current working directory or absolute.

The default name of the build folder is the archive name appended with webAppArchive.

Example: 'OutputDir','D:\Documents\MATLAB\work\mymagicwebAppArchive'

Data Types: char | string

Flag to control build verbosity, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • If you set this property to 'on', then the MATLAB command window displays progress information indicating compiler output during the build process.

  • If you set this property to 'off', then the command window does not display progress information.

Example: 'Verbose','On'

Data Types: logical

Output Arguments

collapse all

Build results, returned as a compiler.build.Results object. The Results object contains:

  • Build type, which is 'webAppArchive'

  • Path to the compiled web app archive file

  • Build options, specified as a WebAppArchiveOptions object

Introduced in R2020b