jdk4py

21.0.8.2 · active · verified Thu Apr 16

jdk4py is a Python library that bundles a specific version of the Java Development Kit (JDK) within a Python package, providing convenient access to the Java runtime directly from Python environments. It is often used to simplify the deployment of Python applications that depend on Java Virtual Machine (JVM)-based components, such as data analytics platforms. The library's versioning scheme reflects the bundled JDK version (the first three numbers) and its own API version (the fourth number), with frequent releases that generally align with upstream JDK updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use the `JAVA`, `JAVA_HOME`, and `JAVA_VERSION` constants to interact with the bundled JDK, including executing a simple Java command using Python's `subprocess` module.

import subprocess
from jdk4py import JAVA, JAVA_HOME, JAVA_VERSION

print(f"JDK Home: {JAVA_HOME}")
print(f"Java Executable: {JAVA}")
print(f"JDK Version: {JAVA_VERSION}")

# Example of running a Java command (e.g., getting version)
try:
    result = subprocess.run(
        [JAVA, "-version"],
        capture_output=True,
        check=True,
        text=True
    )
    # Java -version typically prints to stderr
    print("Java Version Output:\n", result.stderr.strip())
except subprocess.CalledProcessError as e:
    print(f"Error running Java command: {e.stderr}")
except FileNotFoundError:
    print("Java executable not found. Is jdk4py installed correctly?")

view raw JSON →