Use Ant build under Eclipse

Source: Internet
Author: User

The current eclipse is integrated with ant, but how can you use ant under Eclipse? If you use ivy, you need to join Ivy-2.2.0.jar

1. Create a new build.xml in the project root directory


Common Properties for project are:--name:project name (does not have to be fixed)--default: The task name entered by default when the file is run
3. Within the Project tab, define task tasks with the same name as default:<target name= "All" depends= "Init,compile" ></task>the common properties of target are:--name: The name of this task--depends: The task that this task has since been called, which means that the task specified by depends is automatically executed when this task is invoked, and then the task is executed
4. Also create a task named Init in project and customize the tasks in it:<target name= "Init" ><mkdir dir= "build/classes"/></target>the common properties of mkdir are:--dir: Represents the path to the directory to be created (contains the directory to be created)
5. Also create a task named compile in project and customize the tasks in it:<target name= "Compile" ><javac srcdir= "src" destdir= "build/classes" ><classpath><fileset dir= "Webcontent/web-inf/lib" ><include name= "**/*.jar"/></fileset></classpath></javac></target>the common properties of Javac are:--srcdir: Represents the target folder for Java files that need to be compiled, typically the SRC folder of the project--destdir: Indicates the location of the compiled class file, typically build/classes
If you need to include some jar files, you need to specify them through the Classpath file. build.xml File

<pre name= "code" class= "HTML" ><span style= "FONT-SIZE:14PX;" > <?xml version= "1.0" encoding= "UTF-8"?> [name= "Helloword"] indicates the name of the project [basedir=]. The root directory [default= "run] means that the default is run <project name=" Helloword "default=" Run "basedir=". " > [Define a src directory as defined variables] <property name= "src" value= "src"/> <property name= "dest" value              = "Classes"/> <property name= "Hello_jar" value= "Hello1.jar"/> <target name= "Init" >  [Create a file classes] <mkdir dir= "${dest}"/> </target> [compile] <target          Name= "Compile" depends= "init" > <javac srcdir= "${src}" destdir= "${dest}"/> </target> [Play Jar package] <target name= "Build" depends= "compile" > <jar jarfile= "${hello_jar}" Basedi             R= "${dest}"/> </target> [Run] <target name= "Run" depends= "Build" > <java classname= "Helloword" classpath= "${hello_jar}"/> </target> [delete production files] <tar          Get Name= "clean" > <delete dir= "${dest}"/> <delete file= "${hello_jar}"/> </target> [call target in target] <target name= "rerun" depends= "Clean,run" > <ant target= "clean"/> <ant target= "Run"/> </target> </project>//Create a new file on D drive          , named SRC, creates a Helloword Java class public class Helloword {public static void main (string[] args) in the SRC folder          {System.out.println ("Helloword");      }}//Create a new folder for classes//Put Build.xml in and src sibling directory//Use command line to enter D disk, enter ant to compile, compile successfully, use Ant+target name method to execute, such as Ant run </span>



Use Ant build under Eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.