3.4. Step 4: Create a GAR file with Ant

At this point we have (1) a service interface in WSDL, (2) a service implementation in Java, and (3) a deployment descriptor in WSDD and JNDI telling the Web 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 Web services container? Do we have to copy these files to strategically located directories? And what about the Java files? We haven't compiled those 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 will generate a Grid Archive, or GAR file. This GAR file is a single file which contains all the files and information the Web services container needs to deploy our service and make it available to the whole world. In fact, in the next section we'll instruct the GT4 standalone 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.

3.4.1. 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 buildfile ('Makefile' in the make jargon). This buildfile 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:

Figure 3.1. Generating a GAR file with Ant

Generating a GAR file with Ant

As you can see, Ant generates the GAR directly from the three sets of source files. Internally, it is carrying out all the steps listed earlier, sparing us the cumbersome task of doing them ourselves. In a GT4 project, Ant uses two sets of buildfiles: a couple of buildfiles which are a part of GT4, and a buildfile we'll have to write on our own. The GT4 buildfiles cover all the important steps (generating the WSDL code, generating the stubs, ...). Our build file essentially has all the unique parameters of our web service, and a bunch of calls to the GT4 buildfiles.

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

3.4.2. The globus-build-service script and buildfile

Throughout the tutorial, we won't have to write a separate buildfile for each of our services. We will be relying on the globus-build-service script and buildfile, one of the tools developed as part of the Globus Service Build Tools (GSBT) project. This tool will allow us to create a GAR file with minimal effort, and without having to modify an Ant buildfile every time we move on to the next example. A copy of globus-build-service is included with the examples bundle, and more information on the tool can be found on the GSBT website (http://gsbt.sourceforge.net/).

3.4.3. Creating the MathService GAR

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

./globus-build-service.sh -d <service base directory> -s <service's WSDL file>
[Note]

Make sure you have an environment variable called GLOBUS_LOCATION pointed to your Globus Toolkit root (the script depends on this)

[Note]

Windows users can use a Python build script included with the downloadable tutorial files (and also a part of the GSBT project). If you prefer to use the Python script, simply replace globus-build-service.sh with globus-build-service.py in all the following examples.

The "service base directory" is the directory where we placed the deploy-server.wsdd file, and where the Java files can be found (inside an impl directory). To build the first example we simply need to do the following:

./globus-build-service.sh \
	-d org/globus/examples/services/core/first/ \
	-s schema/examples/MathService_instance/Math.wsdl

globus-build-service also allows us to use a shorthand notation which is much easier (and faster) to use. For example, to build our first example and generate its GAR file, we simply need to do the following:

./globus-build-service.sh first
[Note]

Make sure you run this from $EXAMPLES_DIR.

We will be able to use this shorthand notation with all the examples included in the tutorial. However, this shorthand notation will work because the examples bundle includes a file that maps an abbreviated name (like first) to a specific directory and schema file. To write your own mappings and use the shorthand notation in your own projects, refer to the Globus Service Build Tools website.

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

$EXAMPLES_DIR/org_globus_examples_services_core_first.gar