查找Java¶
寻找爪哇
该模块查找是否安装了 Java 并确定包含文件和库的位置。调用者可以设置变量“JAVA_HOME”来明确指定 Java 安装前缀。
另请参阅 FindJNI 模块以查找 Java 本机接口 (JNI)。
在 3.10 版本加入: 添加了对 Java 9+ 版本解析的支持。
在调用此查找模块时指定以下一个或多个组件。请参见下面的示例。
Runtime = Java Runtime Environment used to execute Java byte-compiled applications
Development = Development tools (java, javac, javah, jar and javadoc), includes Runtime component
IdlJ = Interface Description Language (IDL) to Java compiler
JarSigner = Signer and verifier tool for Java Archive (JAR) files
该模块设置以下结果变量:
Java_JAVA_EXECUTABLE = the full path to the Java runtime
Java_JAVAC_EXECUTABLE = the full path to the Java compiler
Java_JAVAH_EXECUTABLE = the full path to the Java header generator
Java_JAVADOC_EXECUTABLE = the full path to the Java documentation generator
Java_IDLJ_EXECUTABLE = the full path to the Java idl compiler
Java_JAR_EXECUTABLE = the full path to the Java archiver
Java_JARSIGNER_EXECUTABLE = the full path to the Java jar signer
Java_VERSION_STRING = Version of java found, eg. 1.6.0_12
Java_VERSION_MAJOR = The major version of the package found.
Java_VERSION_MINOR = The minor version of the package found.
Java_VERSION_PATCH = The patch version of the package found.
Java_VERSION_TWEAK = The tweak version of the package found (after '_')
Java_VERSION = This is set to: $major[.$minor[.$patch[.$tweak]]]
在 3.4 版本加入: 添加了 Java_IDLJ_EXECUTABLE 和 Java_JARSIGNER_EXECUTABLE 变量。
可以使用 find_package() 语法指定所需的最低 Java 版本,例如
find_package(Java 1.8)
注意:${Java_VERSION} 和``${Java_VERSION_STRING}`` 不保证完全相同。例如,某些 Java 版本可能会返回:Java_VERSION_STRING = 1.8.0_17 和 Java_VERSION = 1.8.0.17
另一个例子是 Java OEM,其中:Java_VERSION_STRING = 1.8.0-oem 和``Java_VERSION = 1.8.0``
对于这些组件,设置了以下变量:
Java_FOUND - TRUE if all components are found.
Java_<component>_FOUND - TRUE if <component> is found.
用法示例:
find_package(Java)
find_package(Java 1.8 REQUIRED)
find_package(Java COMPONENTS Runtime)
find_package(Java COMPONENTS Development)