FindJava¶
Finds the Java installation and determines its runtime tools and development components.
在 3.10 版被加入: Support for Java 9+ version parsing.
Components¶
This module supports the following components:
Runtime
Finds the Java Runtime Environment used to execute Java byte-compiled applications.
Development
Finds development tools (
java
,javac
,javah
,jar
, andjavadoc
). Specifying this component also implies theRuntime
component.IdlJ
在 3.4 版被加入.
Finds the Interface Description Language (IDL) to Java compiler.
JarSigner
在 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_FOUND
Boolean indicating whether Java with all specified components is found.
Java_<component>_FOUND
Boolean indicating whether the
<component>
is found.Java_VERSION
Version of Java found. This is set to:
<major>[.<minor>[.<patch>[.<tweak>]]]
.Java_VERSION_MAJOR
The major version of Java found.
Java_VERSION_MINOR
The minor version of Java found.
Java_VERSION_PATCH
The patch version of Java found.
Java_VERSION_TWEAK
The tweak version of Java found (part after the underscore character
_
).Java_VERSION_STRING
Version of Java found, e.g.,
1.6.0_12
.備註
Java_VERSION
andJava_VERSION_STRING
are not guaranteed to be identical. For example, some Java versions may return:Java_VERSION_STRING = 1.8.0_17
andJava_VERSION = 1.8.0.17
.Another example is the Java OEM, with
Java_VERSION_STRING = 1.8.0-oem
andJava_VERSION = 1.8.0
.
快取變數¶
The following cache variables may also be set:
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
在 3.4 版被加入.
The full path to the Java idl compiler.
Java_JAR_EXECUTABLE
The full path to the Java archiver.
Java_JARSIGNER_EXECUTABLE
在 3.4 版被加入.
The full path to the Java jar signer.
Hints¶
This module accepts the following variables:
JAVA_HOME
The 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)