Build Java Engine Programs
General Requirements
To set up your Java® environment for building engine applications:
Add
to your Java class path.matlabroot
/extern/engines/java/jar/engine.jarBuild the engine application with a supported version of JDK™. For version information, see MATLAB Interfaces to Other Languages.
Ensure your JRE™ is not an earlier version than your JDK.
To run Java, add the folder
to your system environment variable. Use these values to determine the variable name
and the path:matlabroot
/bin/arch
Variable
— the name of the environment variable.Path
— the value to assign toVariable
.matlabroot
— the value returned by the MATLAB®matlabroot
command. This command returns the folder where MATLAB is installed.arch
— the value returned by thecomputer("arch")
command.
Operating System | Variable | Path |
---|---|---|
Windows® |
|
|
macOS with Apple silicon |
|
|
macOS with Intel® |
|
|
Linux® |
|
|
Compile and Run Java Code on Windows
Compile your Java code MyJavaCode.java
:
javac -classpath matlabroot\extern\engines\java\jar\engine.jar MyJavaCode.java
Run the Java program MyJavaCode
:
java -classpath .;matlabroot\extern\engines\java\jar\engine.jar MyJavaCode
Set System Path
To set the runtime library path from the Windows command prompt, type the following command.
set PATH=matlabroot\bin\win64;%PATH%
Set the path every time you open the Windows Command Processor.
You can also set the PATH
variable from the System Properties dialog box.
From the Control Panel > System
> Advanced system settings >
Advanced tab, click Environment
Variables. Under System variables, select
Path
and click Edit. Modify
Path
by inserting
; at
the beginning of the Variable
Value. Click OK to close the dialog
boxes, then close the Control Panel dialog box.matlabroot
\bin\win64
Compile and Run Java Code on macOS
Compile the Java code MyJavaCode.java
:
javac -classpath matlabroot/extern/engines/java/jar/engine.jar MyJavaCode.java
Specify Java Library Path and Run Program
To specify the Java library path and run the Java program MyJavaCode
on macOS with Apple silicon, type:
java -Djava.library.path=matlabroot/bin/maca64 -classpath .:matlabroot/extern/engines/java/jar/engine.jar MyJavaCode
On macOS with Intel, type:
java -Djava.library.path=matlabroot/bin/maci64 -classpath .:matlabroot/extern/engines/java/jar/engine.jar MyJavaCode
Compile and Run Java Code on Linux
MATLAB engine API for Java supports only glnxa64
on Linux systems.
To compile Java code MyJavaCode.java
, type:
javac -classpath matlabroot/extern/engines/java/jar/engine.jar MyJavaCode.java
Specify Java Library Path and Run Program
If a compatible GCC library is in the search path, you can add
to
the Java library search path and run the examples without setting the
matlabroot
/bin/glnxa64LD_LIBRARY_PATH
variable. For information on supported
compilers, see Supported and
Compatible Compilers.
To specify the Java library path and run the Java program MyJavaCode
, type:
java -Djava.library.path=matlabroot/bin/glnxa64 -classpath .:matlabroot/extern/engines/java/jar/engine.jar MyJavaCode
Set System Variable and Run Program
To set the LD_LIBRARY_PATH
variable and run Java program, type:
LD_LIBRARY_PATH = matlabroot/bin/glnxa64:matlabroot/sys/os/glnxa64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
java -classpath .:matlabroot/extern/engines/java/jar/engine.jar matlabroot