FindJava¶
Finds the Java installation and determines its runtime tools and development components:
find_package(Java [<version>] [COMPONENTS <components>...] [...])
Added in version 3.10: Support for Java 9+ version parsing.
Components¶
This module supports optional components, which can be specified with the
find_package() command:
find_package(Java [COMPONENTS <components>...])
Supported components include:
RuntimeFinds the Java Runtime Environment used to execute Java byte-compiled applications.
DevelopmentFinds development tools (
java,javac,javah,jar, andjavadoc). Specifying this component also implies theRuntimecomponent.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.
If no components are specified, the module searches for the Runtime
component by default.
Result Variables¶
This module defines the following variables:
Java_FOUNDAdded in version 3.3.
Boolean indicating whether (the requested version of) Java with all specified components was found.
Java_<component>_FOUNDBoolean indicating whether the
<component>was 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_VERSIONandJava_VERSION_STRINGare not guaranteed to be identical. For example, some Java versions may return:Java_VERSION_STRING = 1.8.0_17andJava_VERSION = 1.8.0.17.Another example is the Java OEM, with
Java_VERSION_STRING = 1.8.0-oemandJava_VERSION = 1.8.0.
Cache Variables¶
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.
Hints¶
This module accepts the following variables:
JAVA_HOMEThe caller can set this variable to specify the installation directory of Java explicitly.
Examples¶
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)