Main Content

Configure YourJavaEnvironment

Before you can package MATLAB®functions into Java®applications or use the generated Java application in a Java development environment, you must ensure that your Java environment is properly configured. You should verify that:

  • 您的系统使用一个版本的Java开发人员的Kit (JDK™) that is compatible with MATLAB.

  • JAVA_HOMEis set to the folder containing the system’s JDK installation.

  • CLASSPATHcontains all of the MATLAB library JAR files and the JAR files for the applications containing your packaged MATLAB code.

  • The MATLAB native library paths are properly configured.

Note

For updated Java system requirements, including versions of Java Developer's Kit (JDK) and Java Runtime Environment (JRE), see the supported compiler page at//www.tianjin-qmedu.com/support/compilers/current_release/.

Install the RequiredJDK

To install the proper version of the JDK:

  1. Verify the version of Java your MATLAB installation is using by running the following MATLAB command:

    version -java
  2. Download a Java Developer's Kit (JDK) with the same major version fromhttps://adoptopenjdk.net/.

  3. Install the JDK.

Note

If you are not developing applications or compiling MATLAB code, you can use the Java Runtime Environment (JRE) instead of the JDK.

Set JAVA_HOME

  1. Set the system environment variable,JAVA_HOME, to point to your JDK installation.

  2. At the MATLAB command prompt, typegetenv JAVA_HOMEto verify that MATLAB is reading the correct version ofJAVA_HOME.

  3. Verify that the folder containing your Java installation has been added to your system路径environment variable.

Set the CLASSPATH

To build and run a Java application that uses aMATLAB Compiler SDK™generated package, the system must locate:

  • JAR files containing the MATLAB libraries

  • Applications that you have developed and built with the compiler

Java classes generated by theMATLAB Compiler SDKsoftware use classes contained in thecom.mathworks.toolbox.javabuilderpackage. To use the compiled classes, you should include a file calledjavabuilder.jaron the Java class path. You can find this file in one of the following folders:

MATLAB installed on your system matlabroot/toolbox/javabuilder/jar
MATLAB Runtimeinstalled on your system mcrroot/toolbox/javabuilder/jar

Note

matlabrootrefers to the root folder into which the MATLAB installer has placed the MATLAB files.mcrrootrefers to the root folder under whichMATLAB Runtimeis installed.

In addition, you should add to the JAR files created by the compiler to the class path.

Configure the Native Library Path Variables

操作系统使用the native library path to locate native libraries that are needed to run your Java class. See the following list of variable names according to operating system:

Windows® 路径
Linux® LD_LIBRARY_PATH
Macintosh DYLD_LIBRARY_PATH

The native MATLAB orMATLAB Runtimefiles needed to execute the packaged MATLAB functions called from the Java code must be included on the paths listed by your system’s native library path variable.