MetNet API - Eclipse Quickstart tutorial

Modern IDEs are wonderful creations. However you may need to spend some time getting to know yours. Once you have however, you can get so much more done quickly in a much shorter timespan.

Here we will get you quickly up to speed with Eclipse, a free-of-charge IDE. We're happy to tell you that free in this context does not mean limited. Just like NetBeans, you can even use Eclipse for more than just Java alone. So without further ado, let's get started.

Of course the first thing you should do is download the metnet3.jar file which contains the Java-implementation of the MetNet API. Store it on your local drive (c:\metnet\ would be a good location for it). You'll also need the MySQL driver. If you already have it, that's great. If you don't, you can store it in the same folder as your MetNet library.

Start a new project by going to File > New > Java project. We're not planning to do anything fancy here. Name your project. We chose "MetNet4Java", but you can name it anything you want of course. Leave all the other settings to their default-values. You can change these later to suit your specific needs and preferences. Click the Finish button.

Expand the MetNet4Java folder in the Package Explorer. Right-click on the src folder and add a new Java class. The name can be MetNetTest. Go ahead and add a static void main() method as well by clicking the checkbox. After a few seconds, you should see a screen as the one below:

The first you need to do now is add a reference to the MetNet API .jar-file. In order to do this, right-click on the MetNet4Java project folder in the Package Explorer and select Properties. Click on Java Build Path and select the Libraries tab. Click on the Add External JARs button to add the MetNet library that you stored earlier on your harddisk.

Repeat this process for your MySQL driver

Press the OK button when you're done adding the libraries. Now you're back in the IDE. You can check both files are there by expanding the References Libraries folder.

Now back to your code. Above the declaration of your MetNetTest class, request to import any of MetNet classes that you plan to use. As you start typing import edu., you'll notice that intellicode helps you prevent typos. This automatically rendered assistence is the first sign that you've done everything correctly up to this point. If you don't see the drop-down combobox appear, you shoud revisit the paragraphs above because you may have missed something.

Let's do a real test of the API by writing a simple example program. We'll print out a list of supported MetNet organisms. So start by importing the import edu.iastate.metnet.Organism class. Therefore, alter the content of your void main() to contain the following:

    public static void main(String[] args) {
        Organism[] orgs = Organism.search();
        for (int i = 0; i < orgs.length; i++) {
            System.out.println(orgs[i].name);
        }
    }

When you run the program, you should see a list of organisms currently in the database. If so, congratulations! You may well be on your way to build the next systems biology killer app. Your screen should look something like this:

Back to main