Simple shell for Ant on Linux

As promised in Simple shell for Ant on Windows i would provide a Linux version of the simple Ant shell. So here is a version based on the Bash shell. I’ve written it using Cygwin, but using it on Linux should not be much of a problem. Of course this Linux version has the same functionality as the Windows version.




if [ ! -d "$ANT_HOME" ]
	echo Error: ANT_HOME does not have a valid value
	exit -1

function help
	$ANT_HOME/bin/ant.bat -p -f $project
	echo ""
	echo "Other commands:"
	echo ""
	echo " ?      Show this help."
	echo " help   Show this help."
	echo " q      Stop this shell."
	echo " quit   Stop this shell."
	echo " exit   Stop this shell."
	echo ""

# clear the terminal
echo -e "\0033\0143"

# set the terminal title 
echo -en "\033]2;env - A sample Ant shell\007"

echo "For more information/help, type '?' or 'help'."

while true
	read -p " $ " command
	if [ "$command" == "?" ] || [ "$command" == "help" ]
	else if [ "$command" == "q" ] || [ "$command" == "quit" ] || [ "$command" == "exit" ]
		exit 1
		$ANT_HOME/bin/ant.bat "$command" -f $project -propertyfile 

Simple shell for Ant on Windows

Most of the time an Ant target is started from Eclipse, but i wanted to use Ant on systems without Eclipse too. So i created a script. This Windows script is a simple shell to start Ant targets. This script saves you from writing multiple specific scripts for each target. With this script you can just type the target name and it will be executed. So how advanced this is, depends mostly on the targets in your build.xml.

There are some prerequisites. Ant is needed of course. Ant itself needs the tools.jar for the Java SDK. So that’s needed too. The batch file is kept as simple as possible. It only contains commands for help and closing the shell. All the other commands come from the build.xml. Check the supplied build.xml for samples.

Put all the three files below in one directory to make it work. A Linux version of this script will be available soon.


@echo off

set project=build.xml

if not exist "%ANT_HOME%" goto :anthomenotvalid
if not exist "%JAVA_HOME%" goto :javahomenotvalid

REM make sure this script runs from the directory it's located in
REM change drive first, then change directory
CD %~p0 

title env - A sample Ant shell
echo For more information/help, type '?' or 'help'.

set /p command= $ 

if "%command%" == "?" goto help
if "%command%" == "help" goto help

if "%command%" == "q" goto end
if "%command%" == "quit" goto end
if "%command%" == "exit" goto end

call %ANT_HOME%\bin\ant.bat "%command%" -f %project% -propertyfile

goto start


echo Error: ANT_HOME does not have a valid value

echo Error: JAVA_HOME does not have a valid value

call %ANT_HOME%\bin\ant.bat -p -f %project%
echo Other commands:
echo  ?      Show this help.
echo  help   Show this help.
echo  q      Stop this shell.
echo  quit   Stop this shell.
echo  exit   Stop this shell.
goto start


<project name="Sample Ant file" basedir=".">
	<property environment="env"/>
	<target name="hello" description="This will show hello world.">
		<echo>Hello, world!</echo>
	<target name="myproperty" description="Show the value of myproperty.">
	<target name="hidden">
		<echo>This doesn't show in the because it has no description</echo>
	<target name="properties" description="Show the values of all properties available.">
		<echoproperties />

myproperty=this is some custom value

UPDATE 20-7-2011:
The Linux version is available here.