I am trying to set up a minecraft server, for fun, and want to add a control panel to make managing it easier. Part of this control panel is to run the server FROM the panel to reduce miss-clicking the exit button and what-not. (the minecraft server is a non-runnable .jar file, implying you have to make a .bat to run it from the command line) I know how to run the server inside my program, as well as print the output, here:
ProcessBuilder pb = new ProcessBuilder("java", "-jar", "gscale.jar");
pb.redirectErrorStream(true);
pb.directory(new File("F:\\Documents and Settings\\Administrator\\Desktop"));
System.out.println("Directory: " + pb.directory().getAbsolutePath());
Process p = pb.start();
InputStream is = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
for (String line = br.readLine(); line != null; line = br.readLine()) {
System.out.println( line ); // Or just ignore it
}
p.waitFor();
but, with this, i'm not sure how to implement an input method. for example, if I click a button, it sends the input "stop" to the external jar to stop the server, as it does without this command panel. how would I implement that? the code above I plan to be running in it's own thread, but maybe i'm doing this all wrong?
Thanks in advance!
A Minecraft server is a game server made to specifically host online multiplayer lobbies of Minecraft. By using some software from Mojang Studios, the video game developer of Minecraft, players can choose to use their own computers as Minecraft servers.
Click the Multiplayer tab, and then the Add Server option. Key in the hosting computer's IP address or simply type "localhost" in the server address bar.
Self-hosting a Minecraft server is the cheapest method. It's a free option that allows you run a server on your personal computer and WiFi network. However, there are some cons to self-hosting a Minecraft server. If you want to keep your server online, you will also need to keep the device on.
Looks like the Process
class has a getOutputStream()
method. You could try something like this:
OutputStream os = p.getOutputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
bw.write("stop");
bw.newLine();
bw.flush();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With