Main Content

Dynamically Specify Options to MATLAB Runtime

What Options Can You Specify?

You can pass MATLAB® Runtime options -nojvm, -nodisplay, and -logfile to MATLAB Compiler SDK™ from the client application using two classes in javabuilder.jar:

  • MWApplication

  • MWMCROption

Set and Retrieve MATLAB Runtime Option Values Using MWApplication

The MWApplication class provides several static methods to set MATLAB Runtime option values and also to retrieve them. The following table lists static methods supported by this class.

MWApplication Static MethodsPurpose
MWApplication.initialize(MWMCROption... options);Passes MATLAB Runtime run-time options (see Specifying Run-Time Options Using MWMCROption)
MWApplication.isMCRInitialized();Returns true if MATLAB Runtime is initialized; otherwise returns false
MWApplication.isMCRJVMEnabled();Returns true if MATLAB Runtime is launched with JVM; otherwise returns false
MWApplication.isMCRNoDisplaySet();

Returns true if MWMCROption.NODISPLAY is used in MWApplication.initialize

Note

false is always returned on Windows® systems since the -nodisplay option is not supported on Windows systems.

MWApplication.getMCRLogfileName();Retrieves the name of the log file

Specifying Run-Time Options Using MWMCROption

MWApplication.initialize takes zero or more MWMCROptions.

Calling MWApplication.initialize() without any inputs launches MATLAB Runtime with the following default values.

You must call MWApplication.initialize() before performing any other processing.

These options are all write-once, read-only properties.

MATLAB Runtime Run-Time OptionDefault Values
-nojvmfalse
-logfilenull
-nodisplayfalse
-softwareopenglfalse

Note

If there are no MATLAB Runtime options being passed, you do not need to use MWApplication.initialize since initializing a generated class initializes MATLAB Runtime with default options.

Use the following static members of MWMCROption to represent the MATLAB Runtime options you want to modify.

MWMCROption Static MembersPurpose
MWMCROption.NOJVMLaunches MATLAB Runtime without a JVM®. When this option is used, the JVM launched by the client application is unaffected. The value of this option determines whether or not the MATLAB Runtime should attach itself to the JVM launched by the client application.
MWMCROption.NODISPLAY Launches MATLAB Runtime without display functionality.
MWMCROption.logFile("logfile.dat") Allows you to specify a log file name (must be passed with a log file name).

Pass and Retrieve MATLAB Runtime Option Values from Java Application.  Following is an example of how MATLAB Runtime option values are passed and retrieved from a client-side Java® application:

MWApplication.initialize(MWMCROption.NOJVM,
   MWMCROption.logFile("logfile.dat"),MWMCROption.NODISPLAY);
System.out.println(MWApplication.getMCRLogfileName());
System.out.println(MWApplication.isMCRInitialized());
System.out.println(MWApplication.isMCRJVMEnabled());
System.out.println(MWApplication.isMCRNoDisplaySet()); //UNIX

myclass cls = new myclass();
cls.hello();