Main Content

Dynamically Specify Options to the 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

Setting and Retrieving 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 the MATLAB Runtime run-time is initialized; otherwise returns false
MWApplication.isMCRJVMEnabled();Returns true if the MATLAB Runtime run-time 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 the 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

Note

If there are no MATLAB Runtime options being passed, you do not need to use MWApplication.initialize since initializing a generated class initializes the 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 the 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 the 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).

Passing and Retrieving MATLAB Runtime Option Values from a 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();