Main Content

Define Embedding and Extraction Options for Deployable Java Archive

When you deploy a Java® archive, by default, the archive data is extracted from the JAR file with no separate deployable archive or packageName­mcr folder needed on the target machine. This behavior is helpful when storage space on a file system is limited.

If you don't want to extract deployable archive data by default, you can use either the MWComponentOptions class or environment variables to specify options for extraction and utilization of the deployable archive data.

Extraction Options Using MWComponentOptions Class

Select Options

Choose from the following CtfSource or ExtractLocation instantiation options to customize how MATLAB® Runtime manages deployable archive content with MWComponentOptions:

  • CtfSource — This option specifies where the deployable archive may be found for an extracted component. It defines a binary data stream comprised of the bits of the deployable archive. The following values are objects of some type extending MWCtfSource:

    ValueDescription
    MWCtfSource.NONE

    Indicates that no deployable archive is to be extracted. This option implies that the extracted deployable archive data is already accessible somewhere in your file system. This object is a public, static, final instance of MWCtfSource.

    MWCtfFileSource

    Indicates that the deployable archive data resides within a particular file location that you specify. This class takes a java.io.File object in its constructor.

    MWCtfDirectorySource

    Indicates a folder to be scanned when instantiating the component. If a file with a .ctf suffix is found in the folder that you supply, the deployable archive bits are loaded from that file. This class takes a java.io.File object in its constructor.

    MWCtfStreamSource

    Allows deployable archive bits to be read and extracted directly from a specified input stream. This class takes a java.io.InputStream object in its constructor.

  • ExtractLocation — This option specifies where the extracted deployable archive content is to be located. Since MATLAB Runtime requires all deployable archive content be located somewhere in your file system, use the desired ExtractLocation option, along with the component type information, to define a unique location. A value for this option is an instance of the class MWCtfExtractLocation. You can create an instance of this class by passing a java.io.File or java.lang.String into the constructor to specify the file system location to be used, or you can use one of these predefined, static final instances:

    ValueDescription
    MWCtfExtractLocation.EXTRACT_TO_CACHE

    Use to indicate that the deployable archive content is to be placed in the MATLAB Runtime component cache. This option is the default setting for R2007a and forward.

    MWCtfExtractLocation.EXTRACT_TO_COMPONENT_DIR

    Use when you want to locate the JAR or .class files from where the component has been loaded. If the location is found (e.g., it is in the file system), then the deployable archive data is extracted into the same folder. This option most closely matches the behavior of R2007a and previous releases.

Note

Deployable archives are extracted by default to temp\user_name\mcrCachen.nn.

Set Options

Use the following methods to get or set the location where the deployable archive may be found for an extracted component:

  • getCtfSource()

  • setCtfSource()

Use the following methods to get or set the location where the extracted deployable archive content is to be located:

  • getExtractLocation()

  • setExtractLocation()

Enable MATLAB Runtime Component Cache

If you want to enable the MATLAB Runtime Component Cache for a generated Java class utilizing deployable archive content already resident in your file system, instantiate MWComponentOptions by using the following statements:

MWComponentOptions options = new MWComponentOptions();

// set options for the class by calling setter methods
// on 'options'
options.setCtfSource(MWCtfSource.NONE);
  options.setExtractLocation(
    new MWCtfExtractLocation("C:\\readonlydir\\MyModel_mcr"));

// instantiate the class using the desired options 
MyModel m = new MyModel(options);

Extraction Options Using Environment Variables

Use the following environment variables to change the default settings for the cache size and location of the deployable archive extraction.

Environment VariablePurposeNotes
MCR_CACHE_ROOTWhen set to the location of where you want the deployable archive to be extracted, this variable overrides the default per-user component cache location. This is true for embedded .ctf files only.On macOS, this variable is ignored in MATLAB R2020a and later. The app bundle contains the files necessary for run time.
MCR_CACHE_SIZEWhen set, this variable overrides the default component cache size.The initial limit for this variable is 32M (megabytes), or 1024M starting in R2024b. This may, however, be changed after you have set the variable the first time. Edit the file .max_size, which resides in the file designated by running the mcrcachedir command, with the desired cache size limit.

Related Topics