Step 4: Create a GAR file with Ant

At this point we have (1) a service interface in GWSDL, (2) a service implementation in Java, and (3) a deployment descriptor telling the grid services container how to present (1) and (2) to the outer world. However, all this is a bunch of loose files. How are we supposed to place this in a grid services container? Do we have to copy these files to strategically located directories? And what about the Java file? We haven't compiled it yet!

Fear not, for this is the step when everything comes together in perfect harmony. Using those three files we wrote in the previous three pages we'll generate a Grid Archive, or GAR file. This GAR file is a single file which contains all the files and information the grid services container need to deploy our service and make it available to the whole world. In fact, in the next page we'll instruct a simple grid services container to take the GAR and deploy it.

However, creating a GAR file is a pretty complex task which involves the following:

Don't be scared by all this. Thanks to the hard work of the Globus guys and gals, we can do all this in a single step using a very useful tool called Ant.

Ant

Ant, an Apache Software Foundation project, is a Java build tool. In concept, it is very similar to the classic UNIX make command. It allows programmers to forget about the individual steps involved in obtaining an executable from the source files, which will be taken care of by Ant. Each project is different, so the individual steps are described in a build file ('Makefile' in the make jargon). This build file directs Ant on what it should compile, how it should compile it, and in what order. This simplifies the whole process considerably. In fact, it reduces the number of steps to one! With Ant, all we have to worry about is writing the service interface, the service implementation, and the deployment descriptor. Ant takes care of the rest:

As you can see, Ant generates the GAR directly from the three source files. Internally, it is carrying out all the steps listed earlier, sparing us the cumbersome task of doing them ourselves. In a GT3 project, Ant uses two sets of build files: a couple of build files which are a part of GT3, and a build file we'll have to write on our own. The GT3 build files cover all the important steps (generating the WSDL code, generating the stubs, ...). Our build file essentially has all the unique parameters of our Grid Service, and a bunch of calls to the GT3 build files. At first, it is safe to know practically nothing about Ant and build files; you can usually write a 'generic' build file which will work with more than one Grid Service, and then you won't have to see build files ever again. In fact, this tutorial includes a handy build file that works with all the examples we'll see. However, as you move on to more complex projects, you'll probably need to write custom build files to fine tune the whole build process.

If you want to learn more about Ant, take a look at the Ant Website. It includes plenty of documentation, tutorials, etc.

Our handy multipurpose buildfile and script

For the rest of the tutorial, we are going to use a very handy Ant build file which will work with all the examples we'll see. That way, we won't have to rewrite the build file each time we get to a new example. The build file is included in the downloadable tutorial files (available in the tutorial website). Since this tutorial isn't meant as an Ant tutorial, we won't see what's inside the build file, but feel free to take a look inside.

Since using the Ant file directly implies passing a lot of parameters to Ant, we'll also use a handy shell script which makes things even simpler (also included with the tutorial files).

However, before doing anything, make sure you create a file called build.properties in $TUTORIAL_DIR with the following line:

ogsa.root=path to GT3 installation

Replace path to GT3 installation with the path where you installed GT3. For example:

ogsa.root=/usr/local/gt3

Creating the MathService GAR

Using the provided Ant buildfile and the handy script, building a Grid Service is as simple as doing the following:

./tutorial_build.sh <service base directory> <service's GWSDL file>

The "service base directory" is the directory where we placed the server-deploy.wsdd file, and where the MathImpl.java file can be found (inside an impl directory). More details on this in the Tutorial Directory Structure appendix.

For example, to build our first example and generate its GAR file, we simply need to do the following:

./tutorial_build.sh \
org/globus/progtutorial/services/core/first \
schema/progtutorial/MathService/Math.gwsdl
[Note]

Make sure you run this from $TUTORIAL_DIR.

[Note]

Windows users can use a Python build script originally contributed by Michael Schneider. This script is called tutorial_build.py and is included with the downloadable tutorial files. If you prefer to use the Python script, simply replace tutorial_build.sh with tutorial_build.py in all the following examples.

If everything works fine, the GAR file will be placed in $TUTORIAL_DIR/build/lib. To be exact, the GAR file generated for this example will be the following:

$TUTORIAL_DIR/build/lib/org_globus_progtutorial_services_core_first.gar