This is a WARNING. People say this is given by a misfeature introduced in Ant 1.8. You may need to add another attribute to javac as below
<javac srcdir="src" destdir="build/classes" includeantruntime="false">
This is a WARNING. People say this is given by a misfeature introduced in Ant 1.8. You may need to add another attribute to javac as below
<javac srcdir="src" destdir="build/classes" includeantruntime="false">
Let’s be specific about java in this post. If you start reading this post afresh, please have a look at HowTo 1
+
--src
----HelloAnt.java
--class
----HelloAnt.class
build.xml
public class HelloAnt{
public static void main(String [] args){
System.out.println("Hello Ant");
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="HelloAnt" basedir="." default="jar">
<target name="clean" description="delete all classes">
<delete dir="classes"/>
<delete file="HelloAnt.jar"/>
</target>
<target name="compile" description="compiles the task">
<mkdir dir="classes"/>
<javac srcdir="src" destdir="classes"/>
</target>
<target name="jar" description="jars the task">
<jar destfile="HelloAnt.jar" basedir="classes"/>
</target>
</project>
ant clean
ant compile
ant jar
pandian@Kannan:~/Downloads/ant/sample$ java -cp HelloAnt.jar HelloAnt
Hello Ant
You can download the latest binary from http://ant.apache.org/
JDK is mandatory.
This tutorial examples are taken from Linux. But the commands should be common for all the platforms.
Extract the downloaded ant binary.
Goto ant/bin folder
Try to run ant
pandian@Kannan:~/Downloads/ant$ ant
Buildfile: build.xml does not exist!
Build failed
The Ant binary will contains an xml called fetch.xml. Execute the following command where the fetch.xml is available
pandian@Kannan:~/Downloads/ant/apache-ant-1.8.3$ ant -f fetch.xml -Ddest=system
Buildfile: /home/pandian/Downloads/ant/apache-ant-1.8.3/fetch.xml
.....
BUILD SUCCESSFUL
Total time: 4 minutes 14 seconds
The build instructions are given in XML format. By default ant looks for build.xml. That contains several tasks called targets. To explain the terminologies, A single project has multiple tasks – compile, build jar, upload etc.
A sample build.xml is given below.
The project name is “test project”. It contains a single target called ‘initialize’ (more will be added later)
pandian@Kannan:~/Downloads/ant$ cat build.xml
<?xml version="1.0"?>
<project name="test project" default="initialize">
<target name="initialize">
<echo>This is a test project</echo>
</target>
</project>
Execute ant
pandian@Kannan:~/Downloads/ant$ ant initialize
Buildfile: /home/pandian/Downloads/ant/build.xml
initialize:
[echo] This is a test project
BUILD SUCCESSFUL
Total time: 0 seconds
You can have the important parameters or fields in a property file and import it to build process to make it more flexible. Here is how you can do it.
I have a property file with 3 parameters
pandian@Kannan:~/Downloads/ant$ cat ant.properties
name=grassfield
city=London
country=United Kingdom
I am adding a new target to read and print one of the params.
<target name="get_properties">
<property file="ant.properties"/>
<echo>Imported Properties for name ${name}</echo>
</target>
Now, lets execute the target
pandian@Kannan:~/Downloads/ant$ ant get_properties
Buildfile: /home/pandian/Downloads/ant/build.xml
get_properties:
[echo] Imported Properties for name grassfield
BUILD SUCCESSFUL
Total time: 0 seconds