Download presentation
Presentation is loading. Please wait.
1
Ant
2
What is Ant? The simple definition: A Java-based build tool Like “make in C/C++” for Java The Official Definition: “Apache Ant is a Java-based build tool. In theory, it is kind of like make, without make’s wrinkles.” -- ant.apache.org
3
Deploying your Java program
Scenario Java source files How can a user run your program? User needs to compile Java source files User must know which class is main class Solution 1 Deploy your source files with “README ” file Solution 2 Deploy a program which can compile source files and packing multiple classes into one executable file
4
Why & When should I use? One-time setup hassle provides easy building of a project Cross platform build files support developers working on different operating systems On any project with more than a few source files Every day for every build…
5
build.xml <?xml version="1.0" ?> <project name="SmallWorld" basedir="." default=“jar“> <target name="compile"> <javac srcdir="." destdir="."/> </target> <target name="jar" depends="compile"> <mkdir dir="."/> <jar destfile="./SmallWorld.jar" basedir="."> <manifest> <attribute name="Main-Class" value="SmallWorld"/> </manifest> </jar> </project>
6
Structure of a Build file
Ant uses a build file (called build.xml by default) for its instructions First statement should be <?xml version=“1.0”?>
7
Structure of a Build file
Top level XML tag is ‘project’; there should only be one project tag in a build file <project name=“SmallWorld” default=“jar” basedir=“.”> This specifies that The default target for the project named ‘Test’ is ‘jar’ All activity is relative to the directory specified by basedir
8
<target> A project is made up of a number of targets that tell Ant what it should do Targets consist of a series of tasks that are specific actions for Ant to take Targets have these attributes name (required) depends (comma separated list of other targets) If / unless
9
<target name=“compile” …>
Compile some/all of your source files in this target Feel free to rename it; or have several different compile targets with different names and options <target name="compile"> <javac srcdir="." destdir="."/> </target>
10
<target name=“jar” …>
Creates a jar file from the stuff you’ve built <target name="jar" depends="compile"> <jar destfile="./SmallWorld.jar" basedir="."> <manifest> <attribute name="Main-Class" value="SmallWorld"/> </manifest> </jar> </target> This builds a jar file called (in our test project) ‘smallWorld.jar’ in the directory specified by ./ including everything from the ./ directory A target that depends on another target will demand that the other target get executed first
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.