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:

Runtime

Finds the Java Runtime Environment used to execute Java byte-compiled applications.

Development

Finds development tools (java, javac, javah, jar, and javadoc). Specifying this component also implies the Runtime 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.

If no components are specified, the module searches for the Runtime component by default.

Result Variables

This module defines the following variables:

Java_FOUND

Добавлено в версии 3.3.

Boolean indicating whether (the requested version of) Java with all specified components was found.

Java_<component>_FOUND

Boolean indicating whether the <component> was 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 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.

Cache Variables

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.

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)

See Also

  • The FindJNI module to find Java Native Interface (JNI).

  • The UseJava module to use Java in CMake.