Table of Contents

Class JavaService

Namespace
McServerLauncher.Services
Assembly
McServerLauncher.dll

Detects the machine's Java installations and, if needed, downloads the right version (Adoptium Temurin) for a specific Minecraft version. Works on Windows and Linux.

public class JavaService
Inheritance
JavaService
Inherited Members

Methods

DetectInstalled()

Searches for the java executable in common locations and returns their versions.

public List<JavaService.JavaInstall> DetectInstalled()

Returns

List<JavaService.JavaInstall>

EnsureJavaAsync(int, IProgress<string>?, CancellationToken)

Returns the path to a java executable compatible with the required version. If none is installed, downloads and installs the matching Temurin. Throws if it can't.

public Task<string> EnsureJavaAsync(int requiredMajor, IProgress<string>? log, CancellationToken ct = default)

Parameters

requiredMajor int
log IProgress<string>
ct CancellationToken

Returns

Task<string>

GetGameVersionFromJar(string)

Reads the Minecraft version a server.jar belongs to (modern vanilla jars include it in version.json as "id"). Returns null if it can't be determined.

public string? GetGameVersionFromJar(string jarPath)

Parameters

jarPath string

Returns

string

GetMajorVersion(string)

Runs "java -version" and returns the major version (8, 17, 21, 25...). 0 on failure.

public int GetMajorVersion(string javaExe)

Parameters

javaExe string

Returns

int

GetRequiredJavaFromForgeLibraries(string, string?)

Reads the required Java for a modern Forge server, which has no runnable server.jar of its own (it launches through an @args-file, so GetRequiredJavaFromJar(string) on the configured jar path always fails): the Forge installer keeps the vanilla server jar under "libraries/net/minecraft/server/<version>/", and that jar carries the usual version.json. Prefers the folder matching gameVersion (a leftover from a previous Minecraft version could linger after an upgrade), then tries any other. Returns null if no readable jar is found.

public int? GetRequiredJavaFromForgeLibraries(string serverFolder, string? gameVersion)

Parameters

serverFolder string
gameVersion string

Returns

int?

GetRequiredJavaFromJar(string)

Reads the Java a server.jar needs (modern versions include it in version.json). Returns null if it can't be determined (very old servers or non-standard jars).

public int? GetRequiredJavaFromJar(string jarPath)

Parameters

jarPath string

Returns

int?

IsCompatible(int, int)

An installed Java version is valid for the required one (exact, or newer if 17+).

public static bool IsCompatible(int installed, int required)

Parameters

installed int
required int

Returns

bool