How do I start a java application from a C# application?
I'm working on a minecraft launcher. Is there a general method to start any jar from a C# application?
How do I start a java application from a C# application?
I'm working on a minecraft launcher. Is there a general method to start any jar from a C# application?
You could start the jar file as a new process:
string appData = Environment.GetEnvironmentVariable("APPDATA");
Process.Start(@"java",
@"-Xms512m -Xmx1024m -cp """ + appData + @"\.minecraft\bin\*"" -Djava.library.path=""" + appData + @"\.minecraft\bin\natives"" net.minecraft.client.Minecraft");
This assumes java
is in your PATH
(which happens by default when java is installed). If not, use the absolute path to java.
This is starting the game directly - you can use the minecraft launcher if the user told you where they put it. On windows, that's an exe, so you can start it directly.
Also, APPDATA is a window's variable. For linux, the path is in $HOME
, or ~/
. Also, the params aren't quite the same. Assuming your users will run your app with Mono for linux (or apple). I don't have Mono handy to test the options for you, but you can use
public static bool IsLinux
{
get
{
int p = (int) Environment.OSVersion.Platform;
return (p == 4) || (p == 6) || (p == 128);
}
}
To help you select the correct start path. The above code was found here. I note that the property in the sample above is called IsLinux
, yet the quote from Mono docs says 6
is for Mac OS X. This leads me to believe the property should actually be called IsUnix
(as apple fanatics continue to preach such is the case though apple is as much unix as windows is dos). I don't have macware on hand to test this, I leave that to the student.