A lightweight Windows Service that runs a Java-based Minecraft server (Paper, Spigot, Vanilla, etc.) as a background process. It starts the server automatically when Windows boots, captures the server console output to the Windows Event Log, and shuts the server down cleanly — running save-all and stop — when the service is stopped.
Built on .NET 10 (Microsoft.NET.Sdk.Worker) using the BackgroundService hosting model.
- Runs your Minecraft server unattended as a Windows Service (
start= auto). - Launches
java.exewith configurable JVM arguments (memory limits, GC flags, etc.). - Graceful shutdown: sends
save-allthenstopto the server console and waits for the JVM to exit before the service stops. - Pipes server stdout/stderr into the Windows Event Log (stdout at
Trace, stderr atError). - Validates configuration on startup (Java path, server directory, jar file) and fails fast with clear log messages.
- Windows (x64)
- .NET 10 SDK to build (the published service is self-contained for
win-x64) - A Java runtime (JDK/JRE) compatible with your Minecraft server version
- A Minecraft server jar (e.g. PaperMC) in a dedicated directory
- Administrator rights to install/uninstall the Windows Service
Settings live in appsettings.json under the Minecraft section:
{
"Minecraft": {
"JavaHome": "C:\\Program Files\\Microsoft\\jdk-25.0.3.9-hotspot",
"ServerDirectory": "C:\\MinecraftServer\\PaperMC",
"JarFileName": "paper-26.1.2-69.jar",
"AdditionalArgs": "-Xmx8G -Xms8G"
}
}| Setting | Description |
|---|---|
JavaHome |
Path to the Java installation. java.exe is expected at <JavaHome>\bin\java.exe. If left empty, the JAVA_HOME environment variable is used. |
ServerDirectory |
Directory containing the server jar; used as the process working directory. |
JarFileName |
File name of the server jar inside ServerDirectory. |
AdditionalArgs |
JVM arguments passed before -jar (e.g. memory and GC flags). The server is always launched with nogui. |
The effective command line becomes:
<JavaHome>\bin\java.exe <AdditionalArgs> -jar <ServerDirectory>\<JarFileName> nogui
A separate
appsettings.Development.jsonis used when running with theDevelopmentenvironment.
Remember to accept the Minecraft EULA by setting eula=true in eula.txt inside your server directory.
# Restore and build
dotnet build MinecraftService/MinecraftService.csproj -c Release
# Publish a self-contained build for installation
dotnet publish MinecraftService/MinecraftService.csproj -c Release -r win-x64 --self-containedThe output (including MinecraftService.exe, appsettings.json, and the install/uninstall scripts) is placed in the build/publish output folder.
The repo ships two helper scripts that are copied to the output directory:
Service Install.cmd— creates the service:sc.exe create "Minecraft Service" binpath= "%~dp0MinecraftService.exe" start= autoService Uninstall.cmd— removes the service:sc.exe delete "Minecraft Service"
Steps:
- Build/publish the project.
- Edit
appsettings.jsonin the output folder to match your Java and server paths. - Run
Service Install.cmdas Administrator from the output folder. - Start the service:
(or start it from
sc.exe start "Minecraft Service"
services.msc).
To remove it later, stop the service and run Service Uninstall.cmd as Administrator.
Tip: the install script contains a commented line to enable automatic restart on failure:
sc.exe failure "Minecraft Service" reset= 0 actions= restart/600000
You can run the worker directly without installing it as a service:
dotnet run --project MinecraftService/MinecraftService.csprojThe service logs to the Windows Event Log under the source name Minecraft Service (Application log). Open Event Viewer → Windows Logs → Application to follow startup, the launched command line, server console output, and shutdown progress. Log levels are configured in appsettings.json.
Program.cs— builds the host, binds theMinecraftconfiguration section intoServiceSettings, registers the Windows Service and Event Log logging, and hostsMinecraftWorker.ServiceSettings.cs— configuration model plus aCheckmethod that validatesJAVA_HOME/java.exeand the server jar before startup.MinecraftWorker.cs— theBackgroundServicethat starts the Java process, asynchronously reads its output/error streams into the log, and performs a gracefulsave-all+stopshutdown on service stop.
Licensed under the MIT License.