Main Content

Dynamically Specify Options toMATLABRuntime

What Options Can You Specify?

You can passMATLAB®Runtimeoptions-nojvm,-nodisplay, and-logfiletoMATLAB Compiler SDK™from the client application using two classes injavabuilder.jar:

  • MWApplication

  • MWMCROption

Sett and RetrieveMATLABRuntimeOption Values Using MWApplication

TheMWApplicationclass provides several static methods to setMATLAB Runtimeoption values and also to retrieve them. The following table lists static methods supported by this class.

MWApplication Static Methods Purpose
MWApplication.initialize(MWMCROption...options); PassesMATLAB Runtimerun-time options (seeSpecifying Run-Time Options Using MWMCROption)
MWApplication.isMCRInitialized(); ReturnstrueifMATLAB Runtimeis initialized; otherwise returnsfalse
MWApplication.isMCRJVMEnabled(); ReturnstrueifMATLAB Runtimeis launched with JVM; otherwise returnsfalse
MWApplication.isMCRNoDisplaySet();

ReturnstrueifMWMCROption.NODISPLAYis used inMWApplication.initialize

Note

falseis always returned on Windows®systems since the-nodisplayoption is not supported on Windows systems.

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

Specifying Run-Time Options Using MWMCROption

MWApplication.initializetakes zero or moreMWMCROptions.

CallingMWApplication.initialize()without any inputs launchesMATLAB Runtimewith the following default values.

You must callMWApplication.initialize()before performing any other processing.

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

MATLAB RuntimeRun-Time Option Default Values
-nojvm false
-logfile null
-nodisplay false

Note

If there are noMATLAB Runtime选项是不sed, you do not need to useMWApplication.initializesince initializing a generated class initializesMATLAB Runtimewith default options.

Use the following static members ofMWMCROptionto represent theMATLAB Runtimeoptions you want to modify.

MWMCROption Static Members Purpose
MWMCROption.NOJVM LaunchesMATLAB Runtimewithout 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 theMATLAB Runtimeshould attach itself to the JVM launched by the client application.
MWMCROption.NODISPLAY LaunchesMATLAB Runtimewithout display functionality.
MWMCROption.logFile("logfile.dat") Allows you to specify a log file name (must be passed with a log file name).

Pass and RetrieveMATLABRuntimeOption Values fromJavaApplication.Following is an example of howMATLAB Runtimeoption 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();