Java Tutorial - Java Script :
Build Tools: Ant
Build tools are used to compile and build large complex projects. A build tool will typically do more then just compile code. A build tool creates directory structures, deletes unneeded files, copies files between directories, and performs many of common routine tasks that are needed for managing the building of projects.
Programmers have used the Unix make tool and various work-a-likes for years to build their complex C and C++ programs. But make has it limitations. Make is not standardized across platforms, and make syntax is quirky and can
be difficult to read. On many implementations, errors in makefiles can occur because of arcane errors such as using spaces instead of tabs. Make has another limitation that does not make sense for Java programmers: Make is
designed to execute operating system shell commands, meaning that makefiles are not portable across operating systems. Java of course is designed to be a platform-independent programming language, and as such Java requires
platform-independent build tools. This was a real problem with people working on various Jakarta projects, and so the Jakarta project gave us Ant.
NOTES FOR WINDOWS USERS
Ant is a command-line-oriented tool that is normally used from the command prompt (command.com for Windows 9x and cmd.exe for Windows NT, 2000, and XP). Often, it is desirable not to change the global Windows environment through autoexec.bat or by making changes in the Windows Control Panel,
especially when there is a requirement to support multiple versions of the JDK and other tools. Environment variables set in an instance of the command prompt are local to that instance. This allows you to create shortcuts that will start the command prompt with the environment variables set the way we want them. To do this, first create a batch file that sets the variables as needed. The following is a sample batch file:
rem === save as JavaDev.bat ===
rem configures environment for Java
set JAVA_HOME=c:\jdk1.3.1_06
set ANT_HOME=c:\ant
PATH %PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin
For example, we store the batch files in the c:\batch folder, which is also on the system path. After this file has been created, a shortcut can be added to the desktop. To add the shortcut, right-click on the desktop and choose New ➪ Shortcut. When prompted, browse to the batch file just created. After the shortcut has been saved, the command line will have to be edited. The command line can be edited by right-clicking on the shortcut and selecting properties and then selecting the program or shortcut tab. The command line
for Windows 9x/Me platforms should look like the following:
C:\WIN98\COMMAND.COM /E:2048 /K c:\batch\JavaDev.bat
And for Window NT/2000/XP it should look like:
C:\windows\system32\cmd.exe /K c:\batch\JavaDev.bat
The /E:2048 increases the environment space for environment variables. Many Java programs require a number of large environment variables, so this is recommended for Windows 9x platforms, which by default only provides 256 characters of environment space. The /K keeps the command prompt active
after completion of the batch file.
After this is done, it will be easy to access Java-specific functions from the command prompt launched from the shortcut.
