FindJava¶
Finds the Java installation and determines its runtime tools and development components:
find_package(Java [<version>] [COMPONENTS <components>...] [...])
在 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.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.
If no components are specified, the module searches for the Runtime
component by default.
結果變數¶
該模組定義了以下變數:
Java_FOUND在 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.備註
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.
快取變數¶
The following cache variables may also be set:
Java_JAVA_EXECUTABLEThe full path to the Java runtime.
Java_JAVAC_EXECUTABLEJava 編譯器的完整路徑。
Java_JAVAH_EXECUTABLEThe full path to the Java header generator.
Java_JAVADOC_EXECUTABLEThe full path to the Java documentation generator.
Java_IDLJ_EXECUTABLE在 3.4 版被加入.
Java idl 編譯器的完整路徑。
Java_JAR_EXECUTABLEThe full path to the Java archiver.
Java_JARSIGNER_EXECUTABLE在 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)