java_utils

java_utils contains some functions to help with Java

get_java_information(path: str | PathLike) JavaInformation

Returns Some Information about the given Java Installation

Note

This Function executes the Java executable to determine details such as the version. This might be a security risk.

Example:

java_path = "<path>"
information = minecraft_launcher_lib.java_utils.get_java_information(java_path)
print("Name: " + information["name"])
print("Version: " + information["version"])
print("Java path: " + information["java_path"])
Parameters:

path (str | PathLike) – The Path to the Installation. It must be the Directory. If your Java executable is e.g. /usr/lib/jvm/java-19-openjdk-amd64/bin/java this Parameter must be /usr/lib/jvm/java-19-openjdk-amd64.

Returns:

A dict with Information about the given java installation

Raises:

ValueError – Wrong path

Return type:

JavaInformation

find_system_java_versions(additional_directories: list[str | PathLike] | None = None) list[str]

Try to find all Java Versions installed on the System. You can use this to e.g. let the User choose between different Java Versions in a Dropdown. macOS is not supported yet.

Example:

for version in minecraft_launcher_lib.java_utils.find_system_java_versions():
    print(version)
Parameters:

additional_directories (list[str | PathLike] | None) – A List of additional Directories to search for Java in custom locations

Returns:

A List with all Directories of Java Installations

Return type:

list[str]

find_system_java_versions_information(additional_directories: list[str | PathLike] | None = None) list[JavaInformation]

Same as find_system_java_version(), but uses get_java_information() to get some Information about the Installation instead of just proving a Path. macOS is not supported yet

Note

This Function executes the Java executable to determine details such as the version. This might be a security risk.

Example:

for version_information in minecraft_launcher_lib.java_utils.find_system_java_versions_information():
    print("Path: " + version_information["path"])
    print("Name: " + version_information["name"])
    print("Version: " + version_information["version"])
    print("Java path: " + version_information["java_path"])
    print()
Parameters:

additional_directories (list[str | PathLike] | None) – A List of additional Directories to search for Java in custom locations

Returns:

A List with Information of Java Installations

Return type:

list[JavaInformation]

View the source code of this module