Skip to content

Commit 07b72ff

Browse files
Fitzxelclaude
andcommitted
fix: resolve java binary path on macOS bundle layout (bump 0.1.1)
Mojang distributes some runtimes on macOS (e.g. jre-legacy) with a bundle structure where the binary lives at jre.bundle/Contents/Home/bin/java instead of the flat bin/java. Scan the manifest entries after download to find the real executable path; add find_cached_java_bin for the cache-hit path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4293c3b commit 07b72ff

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "minecraft-java-rs-core"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
description = "Core library for launching Minecraft Java Edition"
66
repository = "https://github.com/fitzxel/minecraft-java-rs-core"

src/game/java.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub async fn get_java_files(
5757
.join(&component)
5858
.join(&platform);
5959

60-
let java_bin = java_bin_path(&runtime_root);
60+
let java_bin = find_cached_java_bin(&runtime_root);
6161

6262
if java_bin.exists() {
6363
return Ok(JavaDownloadResult {
@@ -124,6 +124,25 @@ pub fn java_bin_path(runtime_root: &Path) -> PathBuf {
124124
runtime_root.join("bin").join(bin)
125125
}
126126

127+
/// Like `java_bin_path` but also checks the macOS bundle layout used by some
128+
/// Mojang runtimes (e.g. jre-legacy): `jre.bundle/Contents/Home/bin/java`.
129+
/// Returns the first path that exists on disk, or the standard path as a
130+
/// fallback so callers can still attempt the download.
131+
fn find_cached_java_bin(runtime_root: &Path) -> PathBuf {
132+
let primary = java_bin_path(runtime_root);
133+
if primary.exists() {
134+
return primary;
135+
}
136+
#[cfg(target_os = "macos")]
137+
{
138+
let bundle = runtime_root.join("jre.bundle/Contents/Home/bin/java");
139+
if bundle.exists() {
140+
return bundle;
141+
}
142+
}
143+
primary
144+
}
145+
127146
fn adoptium_os() -> &'static str {
128147
match std::env::consts::OS {
129148
"linux" => "linux",
@@ -236,7 +255,26 @@ async fn try_mojang(
236255
}
237256
}
238257

239-
let java_bin = java_bin_path(runtime_root);
258+
// Find the java binary by scanning manifest entries — some Mojang runtimes
259+
// on macOS use a bundle layout (e.g. jre.bundle/Contents/Home/bin/java)
260+
// rather than the flat bin/java expected by java_bin_path.
261+
let java_bin = manifest.files.iter()
262+
.filter_map(|(rel_path, entry)| {
263+
if entry.executable != Some(true) {
264+
return None;
265+
}
266+
let p = std::path::Path::new(rel_path);
267+
let fname = p.file_name()?.to_str()?;
268+
let in_bin = p.parent()?.file_name()?.to_str()? == "bin";
269+
if in_bin && (fname == "java" || fname == "javaw.exe") {
270+
Some(runtime_root.join(rel_path))
271+
} else {
272+
None
273+
}
274+
})
275+
.next()
276+
.unwrap_or_else(|| java_bin_path(runtime_root));
277+
240278
Ok(Some(JavaDownloadResult {
241279
java_path: java_bin.to_string_lossy().into_owned(),
242280
files: file_records,

0 commit comments

Comments
 (0)