Home > Software engineering >  C# and Minecraft server launch
C# and Minecraft server launch

Time:10-03

Hey everyone I'm having trouble figuring out if it's possible to have a Minecraft server run in C#. when running the below code it batch file it launches cmd and starts the server normally.

java -Xmx1G -jar spigot-1.17.1.jar -nogui

The problem is I want to run it in C# for a future project

what code/if possible would make this run cause I've tried a few bit's of code similar to this with no success java version is JDK 17.

using System;
using System.Diagnostics;

namespace Cmd
{
class Program
{
static void Main(string[] args)
{
ProcessStartInfo processToRunInfo = new ProcessStartInfo();
processToRunInfo.Arguments = ("java -Xmx1G -jar spigot-1.17.1.jar");
processToRunInfo.CreateNoWindow = true;
processToRunInfo.WorkingDirectory = @"C:\Users\DD\Desktop\Offical MC\Shopping District\";
processToRunInfo.FileName = "BuildTools.jar";
Process process = new Process();
process.StartInfo = processToRunInfo;
    
}

CodePudding user response:

You need to set the filename of the process to "java.exe", as this is the main process to be run. The rest remain as arguments

processToRunInfo.FileName = "java.exe";
processToRunInfo.Arguments = ("-Xmx1G -jar spigot-1.17.1.jar");

You may also have to specify the full path to java.exe.

  • Related