invalid java env var

This commit is contained in:
Nathan
2025-11-19 10:50:23 -07:00
parent c0c82520f1
commit 2819ea6524
2 changed files with 576 additions and 2 deletions

View File

@@ -87,11 +87,62 @@ try {
}
Write-Host "Starting SheepIt client..." -ForegroundColor Cyan
${userLine} Set-Location `$sheepDir
& java -jar `$jarPath -ui text --log-stdout --verbose -gpu OPTIX_0 -login '${safeUser}' -password '${safeKey}'
# Check and fix problematic environment variables that can cause boot class path errors
`$envVarsFixed = `$false
# Check JAVA_HOME - invalid values like '\' or empty can cause issues
if (`$env:JAVA_HOME) {
if (`$env:JAVA_HOME -eq '\' -or `$env:JAVA_HOME.Trim() -eq '' -or -not (Test-Path `$env:JAVA_HOME)) {
Write-Host "Warning: Invalid JAVA_HOME detected ('`$env:JAVA_HOME'). Temporarily unsetting..." -ForegroundColor Yellow
Remove-Item Env:\JAVA_HOME -ErrorAction SilentlyContinue
`$envVarsFixed = `$true
}
}
# Check JAVA_TOOL_OPTIONS - invalid values can cause boot class path errors
if (`$env:JAVA_TOOL_OPTIONS) {
if (`$env:JAVA_TOOL_OPTIONS -eq '\' -or `$env:JAVA_TOOL_OPTIONS.Trim() -eq '') {
Write-Host "Warning: Invalid JAVA_TOOL_OPTIONS detected ('`$env:JAVA_TOOL_OPTIONS'). Temporarily unsetting..." -ForegroundColor Yellow
Remove-Item Env:\JAVA_TOOL_OPTIONS -ErrorAction SilentlyContinue
`$envVarsFixed = `$true
}
}
if (`$envVarsFixed) {
Write-Host "Environment variables fixed. Proceeding with Java launch..." -ForegroundColor Green
}
# Check Java version
try {
`$javaOutput = java -version 2>&1
`$javaVersion = `$javaOutput | Select-Object -First 1
Write-Host "Java version: `$javaVersion" -ForegroundColor Gray
}
catch {
Write-Host "Warning: Could not determine Java version" -ForegroundColor Yellow
}
Set-Location `$sheepDir
# Use -XX:+IgnoreUnrecognizedVMOptions to handle any incompatible JVM args
# This flag helps with Java 9+ compatibility issues
`$javaArgs = @('-XX:+IgnoreUnrecognizedVMOptions', '-jar', `$jarPath,
'-ui', 'text', '--log-stdout', '--verbose',
'-gpu', 'OPTIX_0', '-login', '${safeUser}', '-password', '${safeKey}')
try {
& java @javaArgs
}
catch {
Write-Host ('Java execution error: {0}' -f `$_.Exception.Message) -ForegroundColor Red
Write-Host "If the error persists, try reinstalling Java (Temurin 21 recommended)." -ForegroundColor Yellow
throw
}
}
catch {
Write-Host ('Error: {0}' -f `$_.Exception.Message) -ForegroundColor Red
Write-Host ('Stack trace: {0}' -f `$_.ScriptStackTrace) -ForegroundColor DarkRed
}
"@
}