To set up your Java® environment for building engine applications:
Add
to
your Java class path. matlabroot
/extern/engines/java/jar/engine.jar
Build the engine application with JDK™ 7 or 8.
Ensure your JRE™ is not an earlier version than your JDK.
To run Java, add the folder
to your system environment variable.
matlabroot
/bin/<arch
><
is your computer
architecture. For example, arch
>win64
for 64–bit Microsoft®
Windows® machines, maci64
on macOS, or glnxa64
on Linux®.
matlabroot
is the value returned
by the MATLAB® matlabroot
command.
This command returns the folder where MATLAB is installed.
This table lists the names of the environment variables and the values of the paths.
Operating System | Variable | Path |
---|---|---|
Windows |
|
|
64-bit Apple Mac |
|
|
64-bit Linux |
|
|
Compile your Java code:
javac -classpath matlabroot\extern\engines\java\jar\engine.jar MyJavaCode.java
Run the Java program:
java -classpath .;matlabroot\extern\engines\java\jar\engine.jar MyJavaCode
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
MATLAB engine API for Java supports only maci64
on macOS systems.
Compile the Java code:
javac -classpath matlabroot/extern/engines/java/jar/engine.jar MyJavaCode.java
Specify the Java library path and run Java program in one statement.
java -Djava.library.path=matlabroot/bin/maci64 -classpath .:matlabroot/extern/engines/java/jar/engine.jar MyJavaCode
Set the DYLD_LIBRARY_PATH
variable and run Java program.
For example, using a C shell:
setenv DYLD_LIBRARY_PATH matlabroot/bin/maci64:$DYLD_LIBRARY_PATH java -classpath .:matlabroot/extern/engines/java/jar/engine.jar MyJavaCode
You can put these commands in a startup script, such as ~/.cshrc
.
setenv DYLD_LIBRARY_PATH matlabroot/bin/maci64:$DYLD_LIBRARY_PATH
You can put these commands in a startup script such as ~/.profile
.
DYLD_LIBRARY_PATH=matlabroot/bin/maci64:$DYLD_LIBRARY_PATH export DYLD_LIBRARY_PATH
When using early builds of Java version 1.8.0, such as 1.8.0_111, the
DYLD_LIBRARY_PATH environment variable might not be recognized. If you receive a
java.lang.UnsatisfiedLinkError
exception, set the
java.library.path
explicitly:
java -Djava.library.path=matlabroot/bin/maci64 -classpath .:matlabroot/extern/engines/java/jar/engine.jar MyJavaCode
MATLAB engine API for Java supports only glnxa64
on Linux systems.
Compile Java code:
javac -classpath matlabroot/extern/engines/java/jar/engine.jar MyJavaCode.java
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.
Specify the Java library path and run the Java program in one statement.
java -Djava.library.path=matlabroot/bin/glnxa64 -classpath .:matlabroot/extern/engines/java/jar/engine.jar MyJavaCode
Set the LD_LIBRARY_PATH
variable and run Java program. For example, using a C shell:
setenv LD_LIBRARY_PATH matlabroot/bin/glnxa64:matlabroot/sys/os/glnxa64:$LD_LIBRARY_PATH java -classpath .:matlabroot/extern/engines/java/jar/engine.jar MyJavaCode
You can put these commands in a startup script, such as ~/.cshrc
.
setenv LD_LIBRARY_PATH matlabroot/bin/glnxa64:matlabroot/sys/os/glnxa64:$LD_LIBRARY_PATH
You can put these commands in a startup script such as ~/.profile
.
LD_LIBRARY_PATH=matlabroot/bin/glnxa64:matlabroot/sys/os/glnxa64:$LD_LIBRARY_PATH export LD_LIBRARY_PATH