diff options
| author | 2026-01-16 07:46:13 +0100 | |
|---|---|---|
| committer | 2026-01-16 07:46:13 +0100 | |
| commit | 76ab8c504c3d094b3c9d3b2034a4c16384220926 (patch) | |
| tree | 475967b1171e7fb86f1e39f19e31b3eebe47663f /src-tauri/src/main.rs | |
| parent | 9fafc670ccbce9d1f457bb69d03b40988d98b961 (diff) | |
| download | DropOut-76ab8c504c3d094b3c9d3b2034a4c16384220926.tar.gz DropOut-76ab8c504c3d094b3c9d3b2034a4c16384220926.zip | |
fix(windows): resolve Java executable path issues on Windows
- Add normalize_java_path utility function with Windows-specific handling
- Automatically append .exe extension when missing on Windows
- Use 'where' command to locate java.exe in PATH if not found
- Improve error messages with full path display for debugging
- Apply path normalization in both start_game and install_forge commands
This fixes the "Failed to launch java: program not found" error on Windows
by properly handling Java executable paths, including relative paths,
missing extensions, and PATH resolution.
Reviewed-by: Claude Sonnet 4.5
Diffstat (limited to 'src-tauri/src/main.rs')
| -rw-r--r-- | src-tauri/src/main.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6ea6ece..ec19d0c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -526,12 +526,28 @@ async fn start_game( emit_log!(window, format!("First 10 args: {:?}", &args[..10])); } + // Get Java path from config or detect + let java_path_str = if !config.java_path.is_empty() && config.java_path != "java" { + config.java_path.clone() + } else { + // Try to find a suitable Java installation + let javas = core::java::detect_all_java_installations(&app_handle); + if let Some(java) = javas.first() { + java.path.clone() + } else { + return Err( + "No Java installation found. Please configure Java in settings.".to_string(), + ); + } + }; + let java_path = utils::path::normalize_java_path(&java_path_str)?; + // Spawn the process emit_log!( window, - format!("Starting Java process: {}", config.java_path) + format!("Starting Java process: {}", java_path.display()) ); - let mut command = Command::new(&config.java_path); + let mut command = Command::new(&java_path); command.args(&args); command.current_dir(&game_dir); // Run in game directory command.stdout(Stdio::piped()); @@ -551,7 +567,7 @@ async fn start_game( // Spawn and handle output let mut child = command .spawn() - .map_err(|e| format!("Failed to launch java: {}", e))?; + .map_err(|e| format!("Failed to launch Java at '{}': {}\nPlease check your Java installation and path configuration in Settings.", java_path.display(), e))?; emit_log!(window, "Java process started successfully".to_string()); @@ -1540,7 +1556,7 @@ async fn install_forge( ); } }; - let java_path = std::path::PathBuf::from(&java_path_str); + let java_path = utils::path::normalize_java_path(&java_path_str)?; emit_log!(window, "Running Forge installer...".to_string()); |