Java Reference
In-Depth Information
After completing this chapter you'll know how to
• Compile Java source code to .class files, pack them in a jar, and
install them on a Minecraft server
• Run your local server with a new plugin
• Connect to your local server
Build and Install a Plugin
Now that you have the tools installed, we'll build a simple, basic plugin. It
won't do much as plugins go, but it will make sure you can build and run
your own plugins, and it will act as starting point (or skeleton) for all the
plugins we'll write in this topic.
So how do your typed-in instructions end up running on a Minecraft server?
Here's how the whole process works.
You type Java language instructions (we call that “source code”) and save
them into a text file, and then the Java compiler, javac , reads your text file
and converts it into something the computer can run.
You went through this process already with the simple program
you typed in previously.
For the source code you type into a file named you'll get a
binary (not text) file named CreeperTest.class . A binary file is just a file of numbers
—it makes sense to the computer, but not to humans.
Because a typical program might use lots and lots of class files, you usually
archive a bunch of class files into a jar file, and Java runs the code from the
Java (the java program itself) reads class files and jar files to create a running
process on the computer. With Minecraft, this will be the server process that
your Minecraft clients connect to. For now, the only client will be you.
The following figure shows how these parts all fit together. The javac compiler
takes your Java source code, and definitions it finds in CanaryMod.jar , and pro-
duces a class file. That class file gets packed up with the Canary.inf file into a
jar that is your plugin. Then at runtime, Java starts the server from CanaryMod.jar
and loads your plugin from its jar.
Search WWH ::

Custom Search