Show List

Ant Targets

In Ant, a target is a set of tasks that are executed as a single unit. Targets can depend on other targets, which allows for a specific build flow to be defined. Here's an example of an Ant build file with two targets:

php
Copy code
<project name="MyProject" default="build"> <target name="compile"> <javac srcdir="src" destdir="build/classes"/> </target> <target name="build" depends="compile"> <jar destfile="build/MyProject.jar" basedir="build/classes"> <manifest> <attribute name="Main-Class" value="com.example.MyProject"/> </manifest> </jar> </target> </project>

In this example, there are two targets defined: "compile" and "build". The "compile" target compiles the Java source files in the "src" directory and places the compiled class files in the "build/classes" directory. The "build" target depends on the "compile" target and creates a JAR file for the project using the compiled class files. The JAR file is created in the "build" directory with the name "MyProject.jar". The "Main-Class" attribute is set to specify the main class of the JAR file.

To run a target, you can use the "ant" command followed by the name of the target. For example, to run the "build" target in the example above, you would type:

Copy code
ant build

Ant will then execute the "compile" target first, since it is a dependency of the "build" target, and then execute the "build" target.



Next: Ant Tasks


    Leave a Comment


  • captcha text