Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java: Ant

JavaFAQ Home » Java Installation, tunning, options... Go to all tips in Java Installation, tunning, options...


Bookmark and Share

Ant is the most commonly used "make" facility for Java programs. After editing source programs, it's necessary to recompile. Ant checks the last change date on .class and .java files and recompiles source files where the .class date is older than the corresponding .java file.

Ant also supports many additional tasks, for example, running javadoc to produce documentation, running tests, building jar files, ... The action of ant is determined by a build.xml file. A generic build.xml file is given below that might be appropriate for student programs.

Obtaining and installing Ant

Ant is free from the Apache Software Foundation (ant.apache.org).

To install it on Windows unzip it into a directory (eg, C:ant) and set the following three environment variables (JAVA_HOME should be set to where your JDK directory is). Installation instructions can be found at ant/docs/manual/index.html in the ant directory and online.

Environment variables

The environment variables ANT_HOME, JAVA_HOME, and PATH must be set (eg, Settings - Control Panel - System - Advanced - Environment Variables - System Variables).

   ANT_HOME=c:ant
   JAVA_HOME=c:jdk1.4.2_04
   To PATH add %ANT_HOME%in

Usage

Ant can be used from many IDEs, but I typically use it from a DOS/Command window.

  1. Set up ant as above.
  2. Copy build.xml (see below) into your project directory.
  3. Open a DOS/Command window and move (cd) to the directory containing your source files.
  4. Type ant to compile your source files. The source="1.4" option is already specified so assertions are enabled at compile time.
  5. I use a text editor and flip back and forth between editing and the DOS window to make changes, fix bugs, etc.
  6. Run the program with "java -ea YourProg" ("-ea" enables run-time assertions).

Simple build.xml file

For simple development where the source and object files are in the same directory and there's no explicit package (typical student project organization), the following build.xml file can be used. This works correctly if all top-level classes are in separate files. The following ant commands can be used.

ant Compiles source files (defaults to build).
ant build Compiles source files. Same as above.
ant docs Creates javadoc documentation in a docs directory. It creates the docs directory if necessary. docs/index.html is the root of the documentation.
ant clean Deletes all .class files and the docs directory. This must be done whenever a class has been renamed or removed, before final builds, and just every so often to help detect "code rot".


 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy