James Williams
LinkedInMastodonGithub

Setting Up Your Development Environment

There is good chance that if you are undertaking this journey into PlayN and NaGaDeMo with me, you are working Java developer and already have much of the software we'll discuss in this post already set up. But there is also a chance that you could be a developer who only knows about Java in the abstract or "coded it in college." If you fall into the latter category, this post is for you.

Installation methods differ slightly from platform to platform, so for simplicity I will assume that you are using an *NIX (Linux or OSX). I prefer *NIXes because they have to ability to use package managers. Package managers decrease the work needed to install and remove libraries and applications on a user's system. While Windows does not yet have a robust package management system, everything I discuss is possible, with a little more effort.

Get Homebrew (OS X only, optional)

Homebrew is a package management system that provides a simple and lightweight means to install free and open source software. Library dependencies can be installed or removed with a single command. All formulas, Homebrew's term for a file explaining home to install the library or application, are written in Ruby so it's easy to edit or add your own.

Though much of the OS X developer mindshare seems to be in favor of Homebrew, I would be remiss if I didn't mention the older alternative MacPorts. Install homebrew using the instructions here.

Get Java

If you don't already have Java, go get it. We will be running and compiling applications so we need the version labeled JDK, short for Java Development Kit.

If you are using a Linux distribution, more often than not, you have easy access to the most current versions of Java. For Ubuntu, the command is

    sudo apt-get install openjdk-7-jdk

Users on OS X Snow Leopard (10.6) will find that Java 7 requires Lion. A workaround is to install Java from this site which maintains OpenJDK builds for older systems. Homebrew doesn't have formulas for OpenJDK at this time.

Get Maven (and Ant)

Maven is a build automation system that manages all parts of the software development life cycle from compiling to dependency management to package creation. Ant is a related build automation system with slightly different philosophy.

Ant uses XML files that describe a build and its tasks(how to do a certain thing). There are a set of default set of keywords that can be used inside tasks but it is the developer's job to define the tasks and structure of the application and manage dependencies. For a complex project, this can get tedious real fast.

Maven, on the other hand, uses a small XML file to provide metadata about the project. As long as the project follows a predefined structure, you don't have to tell Maven how to, for instance, build a jar, war, or ear of an application. If a goal, Maven parlance for a task, doesn't already exist, you can create your own. Maven also uses central repositories that store libraries and their dependencies allowing you to just package your source code and rely on Maven to intelligently retrieve what it needs. Once you know how one Maven project works, you know how 99% of them will work.

Maven can interoperate with Ant in some respects. Most Maven installations will bundle Ant as well. PlayN allows you to build using either Ant or Maven. Listed below are the commands for installing Maven. Windows users please navigate to http://maven.apache.org.

    // Ubuntu or Debian
    sudo apt-get install maven2

    // Homebrew
    brew install maven

Get Git

Git is a popular open source source control that's used by a large number of software projects. Many of them online distribute their source code using git so it's a good thing to have. Install git with one of the below commands:

   // Ubuntu or Debian
    sudo apt-get install git-core

    // Homebrew
    brew install git

Get PlayN

If you are just joining this series, refer to this post for how and why I chose PlayN. Now that we have reviewed all the supporting libraries, we can get to the main event: PlayN. Install PlayN and PlayN-Samples using the following commands:

    git clone https://code.google.com/p/playn
    git clone https://code.google.com/p/playn-samples

Now change to the playn-samples and test the install:

    cd playn-samples/showcase
    mvn test

If you see a Java window prompting you to make a selection and have no errors, you're all set. :)