Section 9.3. Obtaining and Installing Ant


9.3. Obtaining and Installing Ant

You can obtain ant from the Apache Web site.[3] Which version you download will depend on your system and your needs. There are stable releases and daily builds. Unless you have a compelling need for a feature not yet in a stable release, we would suggest you stick with the most recent stable release. As of this writing, that is version 1.5.1.

[3] http://ant.apache.org/

If you are using RedHat, or another Linux distribution that uses the RedHat Package Manager, rpm, then the simplest way to install would be to download the RPMs linked from the Web site and install those:

 $ rpm -i ant-1.5.1-3jpp.noarch.rpm 

You have two other options besides the trusty old RPM method. First, you may download a binary tarball, a word often used for a compressed file created with the tar utility, or you may download and compile the ant source code.

Let's take these each in turn.

9.3.1. Installing a Binary Tarball

Binary distributions of ant are available in .zip, .tar.gz, and .tar.bz2 formats. Utilities are available for all of these formats for Linux, although you will find that generally .zip files are intended for Windows machines and .tar.gz and .tar.bz2 for UNIX systems. The .gz format is decompressed with the gzip utility and .bz2 files with the bzip2 utility. The bzip2 compression algorithm produces better compression, while gzip is "more common." If you have a modern Linux distribution, you almost certainly have both installed already.

Once you have the archive file downloaded, you should download one of the files linked next to it. These are cryptographic hashes of the legitimate archive file so you may be (more) assured that the software is the software you think it is. The first, PGP, is an actual digital signature. If you are already familiar with PGP or GnuPG and are comfortable with them, then by all means use this. It is, as you know, a superior form of validation compared to MD5. But explaining how to use digital signatures and GPG keys is beyond our scope here. As for MD5, however, this is fairly easy.

An MD5 hash is a 128-bit value generated in such a way that it is impossible for two different files of the same length to have the same hash value (actually, the term used in the literature is "computationally unfeasible," but for our purposes that is the same thing). If you run the program md5sum with the tarball file as an argument and you get the same number as the one you downloaded, you may be certain that the file you have is an exact match with the one that was used to produce the number you downloaded from the Web page. Remember that this is all that is proved by this. If both the file server and the Web page have been compromised, then the fact of a match doesn't mean much. A mismatch however proves that one of the two has been compromised and you probably shouldn't use the tarball.

You should get in the habit of verifying checksums and digital signatures where they are supported.

If you are still worried about the dual compromise, well, that's where a PGP digital signature can help. It not only proves the integrity of the data; it also proves the identity of the generator. Learn more about PGP (actually, the Free Software version of it, called GnuPG, at the GnuPG Web site.[4]

[4] http://www.gnupg.org/

Once you have downloaded both the md5 file and the tarball, validate and extract the tarball (Example 9.1).

Note that we did this in a regular user's home directory. If you just wish to use ant yourself, then this is the way to go. If you wish to make ant available to multiple (or all) users on the system, you will want to untar as root and move the resulting directories to locations convenient to other users, such as /usr/local.

Example 9.1. Validating and extracting the ant tarball
 $ cat jakarta-ant-1.5.1-bin.tar.gz.md5 2be27d9e09011bf1cc3d1967ee34f7d1 $ md5sum jakarta-ant-1.5.1-bin.tar.gz 2be27d9e09011bf1cc3d1967ee34f7d1  jakarta-ant-1.5.1-bin.tar.gz $ zcat jakarta-ant-1.5.1-bin.tar.gz | tar xf - $ cd jakarta-ant-1.5.1 $ ls bin           docs         etc          KEYS            lib LICENSE       LICENSE.dom  LICENSE.sax  LICENSE.xerces  README welcome.html  WHATSNEW $ 

Whether for one user or for many, there is a handful of remaining tasks to make ant usable.

9.3.1.1 Environment Variables

The JAVA_HOME environment variable should already be set as a result of setting up your JDK. JAVA_HOME should point at the base of your JDK installation.

The ANT_HOME environment variable should be set to point at the untared installation of ant. In our sample here, it would be ~/jakarta-ant-1.5.1.

Make sure that the bin directory of the ant installation is added to your PATH.

9.3.2. Installing a Source Tarball

We do not encourage you to install ant from source, although we do encourage you to download and study the ant source. It is an excellent sample Java application.

If you must build from source, the start of the process is the same as above. You download the tarball, verify it with GPG or md5sum, then unzip and untar it.

It begins to differ at this point. The ant source package comes with a shell script, build.sh, that actually builds a minimal version of ant and then runs ant to complete the install.

Make sure that the JAVA_HOME and ANT_HOME are set as you want them, then execute build.sh install. Unless you have installed the optional tasks,[5] you will see several warnings about missing classes. You may safely ignore these.

[5] There is a horde of optional tasks. As the name suggests, they are optional. Include these if you need them. This is the only mention they will receive.

As with the installation of other packages built from source, you will need to have appropriate permissions for the target directories. This might mean running the install as root, with all appropriate attention and dread.



    Java Application Development with Linux
    Java Application Development on Linux
    ISBN: 013143697X
    EAN: 2147483647
    Year: 2004
    Pages: 292

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net