Skip to main content

Utilities for using JDK compiling, running on Linux Server.

Project description

PyJDK Documentation

PyJDK is a Python utility library that simplifies the process of managing Java Development Kit (JDK) installations, compiling Java code, packaging JAR files, and running Java applications directly from Python. It automates the tedious tasks involved in setting up and using the JDK, allowing developers to focus on writing code.

Features

  • Automatic JDK Download and Extraction: Specify the JDK version you need, and PyJDK will handle the download and extraction.
  • Compile Java Code: Programmatically compile Java source files from Python.
  • Package JAR Files: Easily package compiled Java classes into executable JAR files.
  • Run JAR Files: Execute JAR files directly through Python scripts.
  • Cleanup Utilities: Clean up downloaded files and build directories to save space.

Installation

Install PyJDK using pip:

pip install pyjdk

Usage

Importing PyJDK

from pyjdk import PyJDK

Initializing PyJDK

Create an instance of the PyJDK class:

jdk = PyJDK(version=8, logging_enabled=True)
  • version: The JDK version to use (available options are 8, 11, or 17). Default is 8.
  • logging_enabled: Enable or disable logging. Default is False.

Listing Available JDK Versions

List all available JDK versions and check their installation status:

jdk.list_versions()

Compiling Java Code

Compile a Java source file:

jdk.compile_code('path/to/YourJavaFile.java')
  • Replace 'path/to/YourJavaFile.java' with the actual path to your Java source file.

Packaging a JAR File

Package compiled classes into a JAR file:

jdk.pack_jar(main_class='com.example.Main', jar_file_path='build/app.jar')
  • main_class: The fully qualified name of the main class (e.g., com.example.Main).
  • jar_file_path: The output path for the JAR file.

Running a JAR File

Run an existing JAR file:

jdk.run_jar('build/app.jar', args=['arg1', 'arg2'])
  • jar_path: The path to the JAR file you want to run.
  • args: A list of arguments to pass to the JAR file.

Cleaning Up

Clean up downloaded JDK files and build directories:

jdk.cleanup()

API Reference

PyJDK Class

  • __init__(self, version=8, download_dir='jdk_download', extract_dir='jdk_extracted', logging_enabled=False)

    Initializes the PyJDK instance.

  • list_versions(self)

    Lists available JDK versions and their installation status.

  • is_installed(self, version)

    Checks if a specific JDK version is installed.

  • compile_code(self, java_file_path)

    Compiles a Java source file.

  • pack_jar(self, main_class, jar_file_path)

    Packages compiled classes into a JAR file.

  • run_jar(self, jar_path, args=None)

    Runs a JAR file with optional arguments.

  • cleanup(self)

    Cleans up download and build directories.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyjdk-1.0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyjdk-1.0.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file pyjdk-1.0.1.tar.gz.

File metadata

  • Download URL: pyjdk-1.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.10

File hashes

Hashes for pyjdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6310448974153cb55cd8295ba779034270f188aaf845ba2d5900ef0678199d93
MD5 c365e81b01f16d1cbc5545a161dc5c68
BLAKE2b-256 1553fb8e485b676d99e8723d62f801cbba7e26bfe9f56c4b38bdd1844f86ebdc

See more details on using hashes here.

File details

Details for the file pyjdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyjdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.10

File hashes

Hashes for pyjdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 026c4eb10498c0a7d5be0902b9bccd6f1f181b23cdefce8085ebc2e6ba923f21
MD5 ce90befb70a3ed6ff263e0454efb4242
BLAKE2b-256 9fc7be9013469c2fe86f0680a4f989ffff370fc9a0a3ef065e1f25fb745596a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page