Finds the Java installation and determines its runtime tools and development components.
Added in version 3.10: Support for Java 9+ version parsing.
This module supports the following components:
RuntimeFinds the Java Runtime Environment used to execute Java byte-compiled applications.
DevelopmentFinds development tools (java, javac, javah, jar, and
javadoc). Specifying this component also implies the Runtime
component.
IdlJAdded in version 3.4.
Finds the Interface Description Language (IDL) to Java compiler.
JarSignerAdded in version 3.4.
Finds the signer and verifier tool for Java Archive (JAR) files.
Components can optionally be specified using the standard syntax with:
find_package(Java [COMPONENTS <components>...])
If no COMPONENTS are specified, the module searches for the Runtime
component by default.
This module defines the following variables:
Java_FOUNDBoolean indicating whether Java with all specified components is found.
Java_<component>_FOUNDBoolean indicating whether the <component> is found.
Java_VERSIONVersion of Java found. This is set to:
<major>[.<minor>[.<patch>[.<tweak>]]].
Java_VERSION_MAJORThe major version of Java found.
Java_VERSION_MINORThe minor version of Java found.
Java_VERSION_PATCHThe patch version of Java found.
Java_VERSION_TWEAKThe tweak version of Java found (part after the underscore character _).
Java_VERSION_STRINGVersion of Java found, e.g., 1.6.0_12.
Note
Java_VERSION and Java_VERSION_STRING are not guaranteed to be
identical. For example, some Java versions may return:
Java_VERSION_STRING = 1.8.0_17 and Java_VERSION = 1.8.0.17.
Another example is the Java OEM, with Java_VERSION_STRING = 1.8.0-oem
and Java_VERSION = 1.8.0.
The following cache variables may also be set:
Java_JAVA_EXECUTABLEThe full path to the Java runtime.
Java_JAVAC_EXECUTABLEThe full path to the Java compiler.
Java_JAVAH_EXECUTABLEThe full path to the Java header generator.
Java_JAVADOC_EXECUTABLEThe full path to the Java documentation generator.
Java_IDLJ_EXECUTABLEAdded in version 3.4.
The full path to the Java idl compiler.
Java_JAR_EXECUTABLEThe full path to the Java archiver.
Java_JARSIGNER_EXECUTABLEAdded in version 3.4.
The full path to the Java jar signer.
This module accepts the following variables:
JAVA_HOMEThe caller can set this variable to specify the installation directory of Java explicitly.
Finding Java:
find_package(Java)
Finding Java with at least the specified minimum version:
find_package(Java 1.8)
Finding Java and making it required (if Java is not found, processing stops with an error message):
find_package(Java 1.8 REQUIRED)
Specifying the needed Java components to find:
find_package(Java COMPONENTS Development JarSigner)