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 are8,11, or17). Default is8.logging_enabled: Enable or disable logging. Default isFalse.
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.
Metadata
Release files for pyjdk 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyjdk-1.0.1.tar.gz | 4.3 kB | Without provenance | Details for pyjdk-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyjdk-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for pyjdk-1.0.1-py3-none-any.whl |
Total release size: 8.5 kB
Release files / pyjdk-1.0.1.tar.gz
| Download URL | pyjdk-1.0.1.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6310448974153cb55cd8295ba779034270f188aaf845ba2d5900ef0678199d93
|
|
BLAKE2b-256 checksum How to use checksums |
1553fb8e485b676d99e8723d62f801cbba7e26bfe9f56c4b38bdd1844f86ebdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.10
|
Release files / pyjdk-1.0.1-py3-none-any.whl
| Download URL | pyjdk-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
026c4eb10498c0a7d5be0902b9bccd6f1f181b23cdefce8085ebc2e6ba923f21
|
|
BLAKE2b-256 checksum How to use checksums |
9fc7be9013469c2fe86f0680a4f989ffff370fc9a0a3ef065e1f25fb745596a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.10
|
Security for pyjdk 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.