It’s been a very busy start to 2015! But to keep the chops sharp I decided to try writing a few CanaryMod plugins. It took some effort to get a basic build environment going so I made a tutorial for creating CanaryMod plugins using Eclipse out of my notes.
It’s been about 12 years since I built anything serious in Java. I mean literally: Java 1.4 was considered new. Anyway it was fun and hopefully not too many errors. Cheers and enjoy!
UPDATE: I’ve moved the article in it’s entirety in the blog post instead. This is mainly a reorg, it does seem this project is dead but retaining this content for posterity.
This is a detailed guide for setting up Eclipse to develop CanaryMod plugins. CanaryMod is a Minecraft server implementation with a powerful API layer on top. Similar in principle to CraftBukkit and Spigot but without the legal baggage.
We will start with setting up the environment, building a simple yet functional plugin and finally publishing to Github. I wrote this tutorial on Mac OS X (go Apple!) but similar instructions should apply for Windows/Linux folks.
- Java SE SDK.
- Eclipse IDE for Java Developers: this tutorial is based on version 4.4. The Java Developer version contains Maven and Git integration that are both necessary for this tutorial.
- A Github account (optional): it’s free! And open source is great.
- Enable JavaDocs from Maven repositories: Eclipse supports referencing JavaDocs from Maven repositories and integrating into your IDE. To enable this integration in Eclipse go to: Preferences > Maven, tick “Download Artifact JavaDoc” and click OK.
Once you have the requirements installed and running, launch Eclipse to get ready to make your first CanaryMod plugin!
Each plugin will be contained in a standalone project in Eclipse. Let’s set that up now:
- In the Eclipse menu, go to: File > New > Java Project.
- Give the project a name - this will be the “marketing” name of your cool plugin, and ideally will match the Github repository name when you’re done.
- Set “Use an execution environment JRE” to JavaSE-1.6. This will be the minimum Java JRE version your plugin runs on. You can target higher Java versions, but will need to note that in your post when you publish your plugin.
- Leave the rest at defaults, click Next.
- Click Finish.
The handbook adds the CanaryLib.jar to the Libraries here. Do not do this, we will pull CanaryLib in as a Maven dependency further on.
Your project is now created, but let’s hook Maven up to CanaryLib so you can begin coding:
- Go to Package Explorer (on the left) and right click your project.
- Go to Configure > Convert to Maven Project.
- Set the group ID to your website’s domain name if you have one (e.g. com.poweredbyjeff).
- Copy the artifact ID down to Name and optionally set a description.
- Click Finish. You should now be able to see a pom.xml file in your Package Explorer.
Double-click to open the pom.xml file. In the Overview tab:
- Copy/paste http://repo.visualillusionsent.net/repository/public/ into SCM>URL.
- Under Properties, click Create. Set name to project.build.sourceEncoding and value to UTF-8 , click OK.
- Go to the Dependencies tab. Click Add under Dependencies (not Dependency Management!!).
- Configure fields as follows:
- Group ID = net.canarymod
- Artifact ID = CanaryLib
- Version ID = [1.0.0,)
- Leave the rest as default and click OK.
- Go to the menubar and hit File > Save to save your pom.xml.
More information about Maven can be found in the CanaryMod handbook.
You are now ready to do the fun part - writing your cool plugin! Until I’ve expanded this section, work through the Hello World example in the Canary Handbook.
Remember to ignore the bit about adding CanaryLib at the start; begin from “do the packages” and come back here when you’re ready to create a jar.
The “package” target is the one that actually creates the jar file, but unfortunately isn’t in the default list of Run targets. To build the jar the first time, go to the Package Explorer:
- Right click your project > Run As… > Maven Build…
- Put the word “package” in the goal box.
- Click run.
After this first run, you can just use Run As… > Maven Build (note the missing elipsis) to rebuild your jar file. Happy plugineering!
- Make a tl,dr version that bootstraps a project (possibly a pre-made pom.xml generator or ready for import Eclipse project).
- Do rest of plugin creation instead of referring to handbook.
- Write up Github publishing portion.
- Wrote page. Drank beer.
This guide is largely inspired by the official CanaryMod handbooks. Kudos to the relatively small CanaryMod team for building and continuing to maintain such a large project!