Running Minecraft as a Domino Server Task
Thu Jan 13 13:57:51 EST 2011
A couple months back, I started getting into the wonderful game Minecraft, which I heartily recommend. Since I really just wanted to play the multiplayer one, I decided to try setting up my own server. The actual setup is very easy - drop the minecraft_server.jar file from their download page somewhere on your computer and launch it. The tough part was making sure it'd do real server stuff like, primarily, launching automatically at startup.
I looked around a bit for ways to create normal Windows services ro run a Java app, but the process I found looked painful. Then, I realized that I already HAVE a server capable of running Java-based tasks with aplomb - Domino. After not a lot of searching, I found the perfect starting point: http://nsftools.com/tips/JavaAddinTest.java.
Now, I had a couple choices for how I could implement this: I could extract the JAR and figure out how to run the server from the raw classes, essentially writing my own server; I could include the JAR in my project and run the main(...) method of the server class; or I could go the "easy" route and just run the Java task externally. Though the first two would be interesting and are potentially something I'll look into down the line, I went with the final option and it's been serving me pretty well.
Basically, the Java task, when loaded, does a system call to run java.exe to load the server and attaches a couple stream readers to that to read in the standard and error output from the task (error-out from Minecraft appears to include tons of non-error information).
That was sufficient to get it up and running, but I decided to be a little tricker. I set up a database to house reports and config parameters (yes, yes, I know you're not supposed to put database file paths in code, but meh). That way, I can keep a log of all the messages in a searchable format, keep track of the users that have logged in and their last login times, and store parameters like the memory sizes and Java and JAR paths without having to re-edit the server task code for every change.
It's been working out pretty well! I've been working on an XPages UI along side it for viewing the information and sending along server messages, and I'll eventually put in an editor for the .properties file the server uses for its startup preferences.
Here's the (likely bug-ridden) code I'm using: