Fix MfApi Java discovery via SonicHome JRE and ship prebuilt tool.
MfApi restart/list no longer requires system JAVA_HOME or javac when Sonic ships a JRE and Tools/SonicMfContainerTool.jar is present. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -130,6 +130,17 @@ public sealed class SonicConnection
|
|||||||
/// <summary>Sonic-Installationsroot, z.B. "C:\Sonic\MQ10.0" (enthält lib\*.jar für MfApi).</summary>
|
/// <summary>Sonic-Installationsroot, z.B. "C:\Sonic\MQ10.0" (enthält lib\*.jar für MfApi).</summary>
|
||||||
public string SonicHome { get; init; } = @"C:\Sonic\MQ10.0";
|
public string SonicHome { get; init; } = @"C:\Sonic\MQ10.0";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Optional: JRE/JDK-Home (z.B. C:\Sonic\MQ10.0\jre) oder Pfad zu java.exe.
|
||||||
|
/// Leer = automatische Suche (JAVA_HOME, PATH, SonicHome\jre, Program Files\…).
|
||||||
|
/// </summary>
|
||||||
|
public string JavaHome { get; init; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Optionaler direkter Pfad zu java.exe (überschreibt JavaHome wenn gesetzt).
|
||||||
|
/// </summary>
|
||||||
|
public string JavaPath { get; init; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Optionaler Pfad zu Sonic-Client-JARs für MfApi (mgmt_client.jar etc.).
|
/// Optionaler Pfad zu Sonic-Client-JARs für MfApi (mgmt_client.jar etc.).
|
||||||
/// Leer = SonicHome\lib.
|
/// Leer = SonicHome\lib.
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ public sealed class SonicManagementClient : IDisposable
|
|||||||
$"über {_connection.ConnectionUrl} fehlgeschlagen.\n" +
|
$"über {_connection.ConnectionUrl} fehlgeschlagen.\n" +
|
||||||
$"Fehler: {error}\nAusgabe: {output}\n" +
|
$"Fehler: {error}\nAusgabe: {output}\n" +
|
||||||
"Voraussetzungen: Domain Manager erreichbar, SMC-Logins korrekt, " +
|
"Voraussetzungen: Domain Manager erreichbar, SMC-Logins korrekt, " +
|
||||||
"Java/JDK + Sonic-Client-JARs (SonicHome\\lib), Container online.");
|
"JRE (JavaHome/SonicHome\\jre/JAVA_HOME) + Sonic-Client-JARs (SonicHome\\lib), Container online.");
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(
|
await Task.Delay(
|
||||||
@@ -290,6 +290,8 @@ public sealed class SonicManagementClient : IDisposable
|
|||||||
WinRmPassword = source.WinRmPassword,
|
WinRmPassword = source.WinRmPassword,
|
||||||
ManagementMode = SonicManagementMode.LocalCmd,
|
ManagementMode = SonicManagementMode.LocalCmd,
|
||||||
SonicHome = source.SonicHome,
|
SonicHome = source.SonicHome,
|
||||||
|
JavaHome = source.JavaHome,
|
||||||
|
JavaPath = source.JavaPath,
|
||||||
MfClientLibPath = source.MfClientLibPath,
|
MfClientLibPath = source.MfClientLibPath,
|
||||||
KnownContainers = source.KnownContainers,
|
KnownContainers = source.KnownContainers,
|
||||||
ManagementHttpPort = source.ManagementHttpPort,
|
ManagementHttpPort = source.ManagementHttpPort,
|
||||||
|
|||||||
@@ -162,25 +162,37 @@ public sealed class SonicMfApiExecutor
|
|||||||
string? javaExe = ResolveJavaExecutable();
|
string? javaExe = ResolveJavaExecutable();
|
||||||
if (javaExe is null)
|
if (javaExe is null)
|
||||||
{
|
{
|
||||||
|
string sonicHint = string.IsNullOrWhiteSpace(_connection.SonicHome)
|
||||||
|
? ""
|
||||||
|
: $" Erwartet z.B. '{Path.Combine(_connection.SonicHome, "jre", "bin", "java.exe")}'.";
|
||||||
return (false, null, null, null,
|
return (false, null, null, null,
|
||||||
"Java nicht gefunden (JAVA_HOME/bin/java.exe oder PATH). " +
|
"Java nicht gefunden. Gesucht: SonicConnection.JavaHome/JavaPath, JAVA_HOME, PATH, " +
|
||||||
"Für MfApi wird ein JRE/JDK benötigt.");
|
"SonicHome\\jre|jdk\\bin\\java.exe, Program Files\\Java|Eclipse Adoptium." +
|
||||||
|
sonicHint +
|
||||||
|
" Für MfApi JavaHome in appsettings setzen oder JRE unter SonicHome nutzen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
string? libDir = ResolveLibDirectory();
|
(string? libDir, string? libError) = ResolveLibDirectoryDetailed();
|
||||||
if (libDir is null)
|
if (libDir is null)
|
||||||
{
|
{
|
||||||
return (false, null, null, null,
|
return (false, null, null, null, libError);
|
||||||
"Sonic-Client-JARs nicht gefunden. SonicHome\\lib oder MfClientLibPath setzen " +
|
|
||||||
$"(aktuell SonicHome='{_connection.SonicHome}', MfClientLibPath='{_connection.MfClientLibPath}'). " +
|
|
||||||
"Benötigt u.a. mgmt_client.jar / mfcontext.jar / sonic_Client.jar.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bevorzugt: vorcompilierte .jar/.class aus Tools\ (kein javac nötig).
|
||||||
|
if (TryResolvePrebuiltTool(out string? prebuiltDir, out string? prebuiltEntry, out string? prebuiltError)
|
||||||
|
&& prebuiltDir is not null && prebuiltEntry is not null)
|
||||||
|
{
|
||||||
|
string classpath = BuildClasspath(libDir, prebuiltEntry);
|
||||||
|
return (true, javaExe, prebuiltDir, classpath, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: zur Laufzeit aus .java kompilieren (braucht javac + Sonic-Libs).
|
||||||
string? sourcePath = ResolveToolSourcePath();
|
string? sourcePath = ResolveToolSourcePath();
|
||||||
if (sourcePath is null)
|
if (sourcePath is null)
|
||||||
{
|
{
|
||||||
return (false, null, null, null,
|
return (false, null, null, null,
|
||||||
"Tools\\SonicMfContainerTool.java nicht gefunden (App-Ausgabeverzeichnis prüfen).");
|
(prebuiltError ?? "Kein vorcompilierter SonicMfContainerTool gefunden.") +
|
||||||
|
" Tools\\SonicMfContainerTool.java/.class/.jar fehlen im Ausgabeverzeichnis.");
|
||||||
}
|
}
|
||||||
|
|
||||||
string workDir = Path.Combine(Path.GetTempPath(), "esb-sonic-mf");
|
string workDir = Path.Combine(Path.GetTempPath(), "esb-sonic-mf");
|
||||||
@@ -191,7 +203,8 @@ public sealed class SonicMfApiExecutor
|
|||||||
|
|
||||||
File.Copy(sourcePath, javaTarget, overwrite: true);
|
File.Copy(sourcePath, javaTarget, overwrite: true);
|
||||||
|
|
||||||
string classpath = BuildClasspath(libDir, workDir);
|
string compileClasspath = BuildClasspath(libDir, null);
|
||||||
|
string runtimeClasspath = BuildClasspath(libDir, workDir);
|
||||||
bool needsCompile = !File.Exists(classFile)
|
bool needsCompile = !File.Exists(classFile)
|
||||||
|| File.GetLastWriteTimeUtc(classFile) < File.GetLastWriteTimeUtc(sourcePath);
|
|| File.GetLastWriteTimeUtc(classFile) < File.GetLastWriteTimeUtc(sourcePath);
|
||||||
|
|
||||||
@@ -201,14 +214,15 @@ public sealed class SonicMfApiExecutor
|
|||||||
if (javac is null)
|
if (javac is null)
|
||||||
{
|
{
|
||||||
return (false, null, null, null,
|
return (false, null, null, null,
|
||||||
"javac nicht gefunden. JDK installieren (nicht nur JRE), " +
|
"Vorcompilierter SonicMfContainerTool fehlt und javac wurde nicht gefunden. " +
|
||||||
"damit SonicMfContainerTool.java kompiliert werden kann.");
|
"JDK installieren oder Tools\\SonicMfContainerTool.jar/.class mit ausliefern. " +
|
||||||
|
$"Gefundene java.exe: {javaExe}");
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessStartInfo compilePsi = new()
|
ProcessStartInfo compilePsi = new()
|
||||||
{
|
{
|
||||||
FileName = javac,
|
FileName = javac,
|
||||||
Arguments = $"-encoding UTF-8 -cp {Quote(BuildClasspath(libDir, null))} -d {Quote(workDir)} {Quote(javaTarget)}",
|
Arguments = $"-encoding UTF-8 -cp {Quote(compileClasspath)} -d {Quote(workDir)} {Quote(javaTarget)}",
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardError = true,
|
RedirectStandardError = true,
|
||||||
@@ -236,42 +250,111 @@ public sealed class SonicMfApiExecutor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (true, javaExe, workDir, classpath, null);
|
return (true, javaExe, workDir, runtimeClasspath, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string? ResolveLibDirectory()
|
private bool TryResolvePrebuiltTool(out string? workDir, out string? classpathEntry, out string? error)
|
||||||
{
|
{
|
||||||
List<string> candidates = [];
|
workDir = null;
|
||||||
|
classpathEntry = null;
|
||||||
|
error = null;
|
||||||
|
|
||||||
|
string[] searchDirs =
|
||||||
|
[
|
||||||
|
Path.Combine(AppContext.BaseDirectory, "Tools"),
|
||||||
|
Path.Combine(Directory.GetCurrentDirectory(), "Tools"),
|
||||||
|
AppContext.BaseDirectory
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (string dir in searchDirs.Where(Directory.Exists))
|
||||||
|
{
|
||||||
|
string jar = Path.Combine(dir, "SonicMfContainerTool.jar");
|
||||||
|
if (File.Exists(jar))
|
||||||
|
{
|
||||||
|
workDir = dir;
|
||||||
|
classpathEntry = jar;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
string classFile = Path.Combine(dir, "SonicMfContainerTool.class");
|
||||||
|
if (File.Exists(classFile))
|
||||||
|
{
|
||||||
|
workDir = dir;
|
||||||
|
classpathEntry = dir;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
error = "Tools\\SonicMfContainerTool.jar/.class nicht gefunden.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (string? Dir, string? Error) ResolveLibDirectoryDetailed()
|
||||||
|
{
|
||||||
|
List<(string Path, string Label)> candidates = [];
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(_connection.MfClientLibPath))
|
if (!string.IsNullOrWhiteSpace(_connection.MfClientLibPath))
|
||||||
{
|
{
|
||||||
candidates.Add(_connection.MfClientLibPath);
|
candidates.Add((_connection.MfClientLibPath, "MfClientLibPath"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(_connection.SonicHome))
|
if (!string.IsNullOrWhiteSpace(_connection.SonicHome))
|
||||||
{
|
{
|
||||||
candidates.Add(Path.Combine(_connection.SonicHome, "lib"));
|
candidates.Add((Path.Combine(_connection.SonicHome, "lib"), "SonicHome\\lib"));
|
||||||
candidates.Add(_connection.SonicHome);
|
candidates.Add((_connection.SonicHome, "SonicHome"));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string dir in candidates.Where(Directory.Exists))
|
List<string> checkedPaths = [];
|
||||||
|
foreach ((string path, string label) in candidates)
|
||||||
{
|
{
|
||||||
if (Directory.EnumerateFiles(dir, "*.jar", SearchOption.TopDirectoryOnly).Any())
|
checkedPaths.Add($"{label}='{path}'");
|
||||||
|
if (!Directory.Exists(path))
|
||||||
{
|
{
|
||||||
return dir;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Directory.EnumerateFiles(path, "*.jar", SearchOption.TopDirectoryOnly).Any())
|
||||||
|
{
|
||||||
|
return (path, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
string sonicHome = _connection.SonicHome ?? string.Empty;
|
||||||
|
bool sonicHomeExists = !string.IsNullOrWhiteSpace(sonicHome) && Directory.Exists(sonicHome);
|
||||||
|
string libPath = string.IsNullOrWhiteSpace(sonicHome)
|
||||||
|
? "(SonicHome leer)"
|
||||||
|
: Path.Combine(sonicHome, "lib");
|
||||||
|
|
||||||
|
if (sonicHomeExists && Directory.Exists(libPath)
|
||||||
|
&& !Directory.EnumerateFiles(libPath, "*.jar", SearchOption.TopDirectoryOnly).Any())
|
||||||
|
{
|
||||||
|
return (null,
|
||||||
|
$"Sonic-Client-JARs fehlen unter '{libPath}' (Ordner existiert, aber keine *.jar). " +
|
||||||
|
"MfApi braucht u.a. mgmt_client.jar / mfcontext.jar / sonic_Client.jar. " +
|
||||||
|
"MfClientLibPath auf den korrekten Lib-Ordner setzen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string BuildClasspath(string libDir, string? extraDir)
|
if (sonicHomeExists && !Directory.Exists(libPath))
|
||||||
|
{
|
||||||
|
return (null,
|
||||||
|
$"SonicHome='{sonicHome}' gefunden, aber Lib-Ordner fehlt: '{libPath}'. " +
|
||||||
|
"Sonic-Client-Installation prüfen oder MfClientLibPath setzen " +
|
||||||
|
"(erwartet *.jar, u.a. mgmt_client.jar).");
|
||||||
|
}
|
||||||
|
|
||||||
|
return (null,
|
||||||
|
"Sonic-Client-JARs nicht gefunden. SonicHome\\lib oder MfClientLibPath setzen " +
|
||||||
|
$"(geprüft: {string.Join("; ", checkedPaths)}). " +
|
||||||
|
"Benötigt u.a. mgmt_client.jar / mfcontext.jar / sonic_Client.jar.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string BuildClasspath(string libDir, string? extraEntry)
|
||||||
{
|
{
|
||||||
// Java-Classpath-Wildcard für alle JARs im Lib-Ordner
|
// Java-Classpath-Wildcard für alle JARs im Lib-Ordner
|
||||||
string jars = Path.Combine(libDir, "*");
|
string jars = Path.Combine(libDir, "*");
|
||||||
return string.IsNullOrWhiteSpace(extraDir)
|
return string.IsNullOrWhiteSpace(extraEntry)
|
||||||
? jars
|
? jars
|
||||||
: jars + Path.PathSeparator + extraDir;
|
: jars + Path.PathSeparator + extraEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? ResolveToolSourcePath()
|
private static string? ResolveToolSourcePath()
|
||||||
@@ -286,46 +369,307 @@ public sealed class SonicMfApiExecutor
|
|||||||
return candidates.FirstOrDefault(File.Exists);
|
return candidates.FirstOrDefault(File.Exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? ResolveJavaExecutable()
|
private string? ResolveJavaExecutable()
|
||||||
{
|
{
|
||||||
|
foreach (string? configured in new[] { _connection.JavaPath, _connection.JavaHome })
|
||||||
|
{
|
||||||
|
string? fromConfig = ResolveJavaFromConfiguredPath(configured);
|
||||||
|
if (fromConfig is not null)
|
||||||
|
{
|
||||||
|
return fromConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string? javaHome = Environment.GetEnvironmentVariable("JAVA_HOME");
|
string? javaHome = Environment.GetEnvironmentVariable("JAVA_HOME");
|
||||||
if (!string.IsNullOrWhiteSpace(javaHome))
|
string? fromEnv = ResolveJavaFromHomeDir(javaHome);
|
||||||
|
if (fromEnv is not null)
|
||||||
|
{
|
||||||
|
return fromEnv;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? fromPath = FindOnPath(JavaExeName) ?? FindOnPath("java");
|
||||||
|
if (fromPath is not null)
|
||||||
|
{
|
||||||
|
return fromPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(_connection.SonicHome))
|
||||||
|
{
|
||||||
|
string sonicHome = _connection.SonicHome;
|
||||||
|
string[] direct =
|
||||||
|
[
|
||||||
|
Path.Combine(sonicHome, "jre", "bin", JavaExeName),
|
||||||
|
Path.Combine(sonicHome, "jdk", "bin", JavaExeName),
|
||||||
|
Path.Combine(sonicHome, "JRE", "bin", JavaExeName),
|
||||||
|
Path.Combine(sonicHome, "JDK", "bin", JavaExeName)
|
||||||
|
];
|
||||||
|
foreach (string candidate in direct)
|
||||||
{
|
{
|
||||||
string candidate = Path.Combine(javaHome, "bin", "java.exe");
|
|
||||||
if (File.Exists(candidate))
|
if (File.Exists(candidate))
|
||||||
{
|
{
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FindOnPath("java.exe") ?? FindOnPath("java");
|
// Häufige Layouts: SonicHome\MQ*\jre, SonicHome\jre64, SonicHome\Java\jre, ...
|
||||||
|
string? nested = FindJavaUnderSonicHome(sonicHome);
|
||||||
|
if (nested is not null)
|
||||||
|
{
|
||||||
|
return nested;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? ResolveJavacExecutable(string javaExe)
|
return FindJavaInCommonInstallLocations();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string? ResolveJavacExecutable(string javaExe)
|
||||||
{
|
{
|
||||||
|
string javacName = OperatingSystem.IsWindows() ? "javac.exe" : "javac";
|
||||||
|
|
||||||
string? dir = Path.GetDirectoryName(javaExe);
|
string? dir = Path.GetDirectoryName(javaExe);
|
||||||
if (!string.IsNullOrWhiteSpace(dir))
|
if (!string.IsNullOrWhiteSpace(dir))
|
||||||
{
|
{
|
||||||
string sibling = Path.Combine(dir, OperatingSystem.IsWindows() ? "javac.exe" : "javac");
|
string sibling = Path.Combine(dir, javacName);
|
||||||
if (File.Exists(sibling))
|
if (File.Exists(sibling))
|
||||||
{
|
{
|
||||||
return sibling;
|
return sibling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (string? configured in new[] { _connection.JavaPath, _connection.JavaHome })
|
||||||
|
{
|
||||||
|
string? fromConfig = ResolveToolFromConfiguredPath(configured, javacName);
|
||||||
|
if (fromConfig is not null)
|
||||||
|
{
|
||||||
|
return fromConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string? javaHome = Environment.GetEnvironmentVariable("JAVA_HOME");
|
string? javaHome = Environment.GetEnvironmentVariable("JAVA_HOME");
|
||||||
if (!string.IsNullOrWhiteSpace(javaHome))
|
if (!string.IsNullOrWhiteSpace(javaHome))
|
||||||
{
|
{
|
||||||
string candidate = Path.Combine(javaHome, "bin",
|
string candidate = Path.Combine(javaHome, "bin", javacName);
|
||||||
OperatingSystem.IsWindows() ? "javac.exe" : "javac");
|
|
||||||
if (File.Exists(candidate))
|
if (File.Exists(candidate))
|
||||||
{
|
{
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FindOnPath("javac.exe") ?? FindOnPath("javac");
|
if (!string.IsNullOrWhiteSpace(_connection.SonicHome))
|
||||||
|
{
|
||||||
|
foreach (string root in EnumerateJdkRootsUnderSonicHome(_connection.SonicHome))
|
||||||
|
{
|
||||||
|
string candidate = Path.Combine(root, "bin", javacName);
|
||||||
|
if (File.Exists(candidate))
|
||||||
|
{
|
||||||
|
return candidate;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FindOnPath(javacName) ?? FindOnPath("javac");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? ResolveJavaFromConfiguredPath(string? configured)
|
||||||
|
=> ResolveToolFromConfiguredPath(configured, JavaExeName);
|
||||||
|
|
||||||
|
private static string? ResolveToolFromConfiguredPath(string? configured, string exeName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(configured))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string path = configured.Trim().Trim('"');
|
||||||
|
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
if (path.EndsWith(exeName, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Konfiguriert: ...\bin\java.exe → sibling javac.exe (oder umgekehrt)
|
||||||
|
string? parent = Path.GetDirectoryName(path);
|
||||||
|
if (!string.IsNullOrWhiteSpace(parent))
|
||||||
|
{
|
||||||
|
string sibling = Path.Combine(parent, exeName);
|
||||||
|
if (File.Exists(sibling))
|
||||||
|
{
|
||||||
|
return sibling;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// java ohne Endung (Unix) oder exakter Treffer
|
||||||
|
string fileName = Path.GetFileName(path);
|
||||||
|
if (fileName.Equals(Path.GetFileNameWithoutExtension(exeName), StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| fileName.Equals(exeName, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string fromHome = Path.Combine(path, "bin", exeName);
|
||||||
|
return File.Exists(fromHome) ? fromHome : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? ResolveJavaFromHomeDir(string? home)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(home))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string candidate = Path.Combine(home.Trim().Trim('"'), "bin", JavaExeName);
|
||||||
|
return File.Exists(candidate) ? candidate : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? FindJavaUnderSonicHome(string sonicHome)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(sonicHome))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Direkte Unterordner mit jre/jdk
|
||||||
|
foreach (string root in EnumerateJdkRootsUnderSonicHome(sonicHome))
|
||||||
|
{
|
||||||
|
string candidate = Path.Combine(root, "bin", JavaExeName);
|
||||||
|
if (File.Exists(candidate))
|
||||||
|
{
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<string> EnumerateJdkRootsUnderSonicHome(string sonicHome)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(sonicHome))
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] preferredNames =
|
||||||
|
[
|
||||||
|
"jre", "jdk", "JRE", "JDK", "jre64", "jdk64", "Java", "java"
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (string name in preferredNames)
|
||||||
|
{
|
||||||
|
string path = Path.Combine(sonicHome, name);
|
||||||
|
if (Directory.Exists(path))
|
||||||
|
{
|
||||||
|
yield return path;
|
||||||
|
string nestedJre = Path.Combine(path, "jre");
|
||||||
|
if (Directory.Exists(nestedJre))
|
||||||
|
{
|
||||||
|
yield return nestedJre;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// {SonicHome}\*\jre und {SonicHome}\*\jdk
|
||||||
|
IEnumerable<string> children;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
children = Directory.EnumerateDirectories(sonicHome);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string child in children)
|
||||||
|
{
|
||||||
|
foreach (string leaf in new[] { "jre", "jdk", "JRE", "JDK" })
|
||||||
|
{
|
||||||
|
string nested = Path.Combine(child, leaf);
|
||||||
|
if (Directory.Exists(nested))
|
||||||
|
{
|
||||||
|
yield return nested;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// z.B. ...\jre1.8.0_xxx direkt als Kind
|
||||||
|
string leafName = Path.GetFileName(child);
|
||||||
|
if (leafName.StartsWith("jre", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| leafName.StartsWith("jdk", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
yield return child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? FindJavaInCommonInstallLocations()
|
||||||
|
{
|
||||||
|
string[] roots =
|
||||||
|
[
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
|
||||||
|
@"C:\Program Files",
|
||||||
|
@"C:\Program Files (x86)"
|
||||||
|
];
|
||||||
|
|
||||||
|
string[] vendorFolders =
|
||||||
|
[
|
||||||
|
"Java",
|
||||||
|
"Eclipse Adoptium",
|
||||||
|
"AdoptOpenJDK",
|
||||||
|
"Microsoft",
|
||||||
|
"Amazon Corretto",
|
||||||
|
"Zulu",
|
||||||
|
"BellSoft",
|
||||||
|
"Semeru"
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (string root in roots.Where(r => !string.IsNullOrWhiteSpace(r)).Distinct(StringComparer.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
foreach (string vendor in vendorFolders)
|
||||||
|
{
|
||||||
|
string vendorDir = Path.Combine(root, vendor);
|
||||||
|
if (!Directory.Exists(vendorDir))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// vendor\bin\java.exe
|
||||||
|
string direct = Path.Combine(vendorDir, "bin", JavaExeName);
|
||||||
|
if (File.Exists(direct))
|
||||||
|
{
|
||||||
|
return direct;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (string sub in Directory.EnumerateDirectories(vendorDir)
|
||||||
|
.OrderByDescending(d => d, StringComparer.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
string candidate = Path.Combine(sub, "bin", JavaExeName);
|
||||||
|
if (File.Exists(candidate))
|
||||||
|
{
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
string nestedJre = Path.Combine(sub, "jre", "bin", JavaExeName);
|
||||||
|
if (File.Exists(nestedJre))
|
||||||
|
{
|
||||||
|
return nestedJre;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignore inaccessible vendor dirs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string JavaExeName => OperatingSystem.IsWindows() ? "java.exe" : "java";
|
||||||
|
|
||||||
private static string? FindOnPath(string fileName)
|
private static string? FindOnPath(string fileName)
|
||||||
{
|
{
|
||||||
@@ -339,7 +683,7 @@ public sealed class SonicMfApiExecutor
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string candidate = Path.Combine(dir.Trim('"'), fileName);
|
string candidate = Path.Combine(dir.Trim().Trim('"'), fileName);
|
||||||
if (File.Exists(candidate))
|
if (File.Exists(candidate))
|
||||||
{
|
{
|
||||||
return candidate;
|
return candidate;
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,10 +14,13 @@
|
|||||||
"Username": "Administrator",
|
"Username": "Administrator",
|
||||||
"Password": "Administrator",
|
"Password": "Administrator",
|
||||||
// Standard: Sonic MF Management API (IAgentProxy.restart) – kein WinRM.
|
// Standard: Sonic MF Management API (IAgentProxy.restart) – kein WinRM.
|
||||||
// Benötigt Java/JDK + Client-JARs unter SonicHome\\lib (oder MfClientLibPath).
|
// Benötigt JRE + Client-JARs unter SonicHome\\lib (oder MfClientLibPath).
|
||||||
|
// Java: oft unter SonicHome\\jre – sonst JavaHome/JavaPath setzen (kein systemweites JAVA_HOME nötig).
|
||||||
// Optional-Fallback: "WinRm" / "LocalCmd" (stopcontainer/startcontainer).
|
// Optional-Fallback: "WinRm" / "LocalCmd" (stopcontainer/startcontainer).
|
||||||
"ManagementMode": "MfApi",
|
"ManagementMode": "MfApi",
|
||||||
"SonicHome": "C:\\Sonic\\MQ10.0",
|
"SonicHome": "C:\\Sonic\\MQ10.0",
|
||||||
|
"JavaHome": "",
|
||||||
|
"JavaPath": "",
|
||||||
"MfClientLibPath": "",
|
"MfClientLibPath": "",
|
||||||
"KnownContainers": [
|
"KnownContainers": [
|
||||||
"DE-Test"
|
"DE-Test"
|
||||||
|
|||||||
Reference in New Issue
Block a user