Expand description
The Java module provides functionality for fetching and installing Java runtimes from Mojang’s Piston API. This enables automatic Java runtime management for Minecraft launchers.
§Structures
§JavaManifest
The root structure containing Java runtime information for all supported platforms.
pub struct JavaManifest {
pub linux: Runtimes,
pub linux_i386: Runtimes,
pub macos: Runtimes,
pub macos_arm64: Runtimes,
pub windows_arm64: Runtimes,
pub windows_x64: Runtimes,
pub windows_x86: Runtimes,
}| Field | Type | Description |
|---|---|---|
linux | Runtimes | Runtimes for Linux x64 |
linux_i386 | Runtimes | Runtimes for Linux x86 (32-bit) |
macos | Runtimes | Runtimes for macOS x64 |
macos_arm64 | Runtimes | Runtimes for macOS ARM64 (Apple Silicon) |
windows_arm64 | Runtimes | Runtimes for Windows ARM64 |
windows_x64 | Runtimes | Runtimes for Windows x64 |
windows_x86 | Runtimes | Runtimes for Windows x86 (32-bit) |
§Runtimes
Collection of available Java runtime variants for a platform.
pub struct Runtimes {
pub alpha: Vec<JavaRuntime>,
pub beta: Vec<JavaRuntime>,
pub gamma: Vec<JavaRuntime>,
pub delta: Vec<JavaRuntime>,
pub gamma_snapshot: Vec<JavaRuntime>,
pub epsilon: Vec<JavaRuntime>,
pub legacy: Vec<JavaRuntime>,
pub minecraft_java_exe: serde_json::Value,
}| Field | Type | Description |
|---|---|---|
alpha | Vec<JavaRuntime> | Java runtime alpha (Java 16) |
beta | Vec<JavaRuntime> | Java runtime beta (Java 17) |
gamma | Vec<JavaRuntime> | Java runtime gamma (Java 17) |
delta | Vec<JavaRuntime> | Java runtime delta (Java 21) |
gamma_snapshot | Vec<JavaRuntime> | Java runtime gamma snapshot |
epsilon | Vec<JavaRuntime> | Java runtime epsilon (Java 24+) |
legacy | Vec<JavaRuntime> | Legacy JRE (Java 8) |
minecraft_java_exe | serde_json::Value | Minecraft Java executable metadata |
§JavaRuntime
Represents a specific Java runtime version with its manifest and availability information.
pub struct JavaRuntime {
pub version: Version,
pub manifest: Manifest,
pub availability: Availability,
}| Field | Type | Description |
|---|---|---|
version | Version | Version information |
manifest | Manifest | Download manifest for the runtime |
availability | Availability | Availability/rollout information |
§Version
Version information for a Java runtime.
pub struct Version {
pub name: String,
pub released: chrono::DateTime<chrono::Utc>,
}| Field | Type | Description |
|---|---|---|
name | String | Version name (e.g., “17.0.8”) |
released | DateTime<Utc> | Release timestamp |
§Manifest
Manifest metadata for downloading a Java runtime.
pub struct Manifest {
pub sha1: String,
pub size: usize,
pub url: String,
}| Field | Type | Description |
|---|---|---|
sha1 | String | SHA1 hash of the manifest file |
size | usize | Size of the manifest file in bytes |
url | String | URL to download the manifest |
§Availability
Availability information for a Java runtime.
pub struct Availability {
pub group: u32,
pub progress: u32,
}| Field | Type | Description |
|---|---|---|
group | u32 | Availability group identifier |
progress | u32 | Rollout progress percentage |
§JavaInstallationFile
Represents a single file in a Java runtime installation.
pub struct JavaInstallationFile {
pub name: String,
pub file_type: Option<FileType>,
pub executable: Option<bool>,
pub downloads: Option<Downloads>,
}| Field | Type | Description |
|---|---|---|
name | String | File path relative to the installation directory |
file_type | Option<FileType> | Type of file (file, directory, or link) |
executable | Option<bool> | Whether the file should be marked executable |
downloads | Option<Downloads> | Download information (absent for directories) |
§Downloads
Download options for a Java installation file.
pub struct Downloads {
pub lzma: Option<DownloadItem>,
pub raw: DownloadItem,
}| Field | Type | Description |
|---|---|---|
lzma | Option<DownloadItem> | LZMA compressed download (if available) |
raw | DownloadItem | Uncompressed raw download |
§DownloadItem
Information for downloading a specific file.
pub struct DownloadItem {
pub sha1: String,
pub size: usize,
pub url: String,
}| Field | Type | Description |
|---|---|---|
sha1 | String | SHA1 hash for validation |
size | usize | File size in bytes |
url | String | Download URL |
§FileType
Type of file in the Java installation.
pub enum FileType {
File,
Directory,
Link,
}| Variant | Description |
|---|---|
File | Regular file |
Directory | Directory (no download required) |
Link | Symbolic link |
§Methods
§JavaManifest::fetch()
Fetches the Java runtime manifest from Mojang’s Piston API.
pub async fn fetch() -> Result<Self>Returns: Result<JavaManifest> - The parsed Java manifest containing all available runtimes
§JavaRuntime::get_installation_files()
Fetches the list of files required for installing this Java runtime.
pub async fn get_installation_files(&self) -> Result<Vec<JavaInstallationFile>>Returns: Result<Vec<JavaInstallationFile>> - List of all files in the runtime
§JavaRuntime::install()
Downloads and installs the Java runtime to a specified directory.
pub async fn install(
&self,
directory: impl AsRef<Path>,
parallel: u16,
sender: Option<tokio::sync::mpsc::Sender<MultiDownloadProgress>>,
) -> Result<()>Parameters:
directory- Directory where the Java runtime will be installedparallel- Number of concurrent downloadssender- Optional channel for receiving download progress updates
Returns: Result<()> - Success or error
§Examples
§Fetch Java Manifest
use piston_mc::java::JavaManifest;
#[tokio::main]
async fn main() {
// Fetch the Java runtime manifest from Mojang's Piston API
let manifest = JavaManifest::fetch().await.expect("Failed to fetch Java manifest");
// Access runtimes for a specific platform
let windows_runtimes = &manifest.windows_x64;
// Get the first gamma runtime (Java 17)
if let Some(runtime) = windows_runtimes.gamma.first() {
println!("Java version: {}", runtime);
}
}§Install Java Runtime Without Progress
use piston_mc::java::JavaManifest;
use std::path::Path;
#[tokio::main]
async fn main() {
// Fetch the Java runtime manifest
let manifest = JavaManifest::fetch().await.expect("Failed to fetch Java manifest");
// Get the gamma runtime (Java 17) for Windows x64
if let Some(runtime) = manifest.windows_x64.gamma.first() {
// Define the installation directory
let install_dir = Path::new("target/java/17");
// Install with 50 parallel downloads, no progress reporting
runtime.install(install_dir, 50, None).await.expect("Failed to install Java runtime");
println!("Java runtime installed successfully");
}
}§Install Java Runtime With Progress
use simple_download_utility::MultiDownloadProgress;
use piston_mc::java::JavaManifest;
use std::path::Path;
#[tokio::main]
async fn main() {
// Fetch the Java runtime manifest
let manifest = JavaManifest::fetch().await.expect("Failed to fetch Java manifest");
// Get the gamma runtime (Java 17) for Windows x64
if let Some(runtime) = manifest.windows_x64.gamma.first() {
// Define the installation directory
let install_dir = Path::new("target/java/17");
// Create a channel for receiving download progress updates
let (sender, mut receiver) = tokio::sync::mpsc::channel::<MultiDownloadProgress>(16);
// Start the installation task
let task = runtime.install(install_dir, 100, Some(sender));
// Spawn a separate task to handle progress updates
tokio::spawn(async move {
while let Some(progress) = receiver.recv().await {
// Calculate download completion percentage
let percent = (progress.files_downloaded as f32 / progress.files_total as f32) * 100.0;
// Convert download speed to MB/s
let mb_per_sec = progress.bytes_per_second as f32 / 1024.0 / 1024.0;
println!(
"Installing Java: {:.2}% ({}/{} files) {:.2} MB/s",
percent,
progress.files_downloaded,
progress.files_total,
mb_per_sec
);
}
});
// Await the installation task completion
task.await.expect("Failed to install Java runtime");
println!("Java runtime installed successfully");
}
}§Get Installation Files
use piston_mc::java::JavaManifest;
#[tokio::main]
async fn main() {
// Fetch the Java runtime manifest
let manifest = JavaManifest::fetch().await.expect("Failed to fetch Java manifest");
// Get the legacy runtime (Java 8) for Linux
if let Some(runtime) = manifest.linux.legacy.first() {
// Fetch the list of installation files
let files = runtime.get_installation_files().await.expect("Failed to get installation files");
println!("Java {} requires {} files", runtime, files.len());
// List some files
for file in files.iter().take(10) {
println!(" {}", file.name);
}
}
}§Select Runtime for Current Platform
use piston_mc::java::{JavaManifest, Runtimes};
#[tokio::main]
async fn main() {
let manifest = JavaManifest::fetch().await.expect("Failed to fetch Java manifest");
// Select runtimes based on current platform
let runtimes: &Runtimes = if cfg!(target_os = "windows") {
if cfg!(target_arch = "x86_64") {
&manifest.windows_x64
} else if cfg!(target_arch = "aarch64") {
&manifest.windows_arm64
} else {
&manifest.windows_x86
}
} else if cfg!(target_os = "macos") {
if cfg!(target_arch = "aarch64") {
&manifest.macos_arm64
} else {
&manifest.macos
}
} else {
if cfg!(target_arch = "x86") {
&manifest.linux_i386
} else {
&manifest.linux
}
};
// Get the recommended Java 17 runtime (gamma)
if let Some(runtime) = runtimes.gamma.first() {
println!("Recommended Java runtime: {}", runtime);
}
}§Runtime Types
Mojang provides several Java runtime variants for different Minecraft versions:
| Runtime | Java Version | Minecraft Versions |
|---|---|---|
legacy | Java 8 | 1.0 - 1.16.5 |
alpha | Java 16 | 1.17 - 1.17.1 |
beta | Java 17 | Early 1.18 snapshots |
gamma | Java 17 | 1.18 - 1.20.4 |
gamma_snapshot | Java 17 | Snapshot versions |
delta | Java 21 | 1.20.5+ |
epsilon | Java 24+ | Future versions |
§API Source
The Java runtime manifest is fetched from Mojang’s Piston API:
https://piston-meta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json