Go Using Ant in Eclipse

Source: Internet
Author: User

 using ant in EclipseCategory: JAVA Tools server 2014-08-05 09:59 5507 people read reviews (0) favorite reports Anteclipse

http://286.iteye.com/blog/1909223

Ant is already integrated in eclipse, and we can run ant directly in Eclipse, and what I do here is not to run the written build.xml file directly, but to use the ant plugin to build a build file.

First open Eclipse, click "Window"--"Preferences"-"Ant" in the navigation bar


There are ant code templates, formatting, classpath and other property settings, can be set according to the circumstances of their own, are relatively simple.

We are going to build a build file with a dependent Jar package project, here I take log4j as an example, add log4j to the build path of the Helloant project:



The source code for modifying the Helloant.java is:

Java code
  1. Package Com.ant.hello;
  2. Import Org.apache.log4j.Logger;
  3. Public class Helloant {
  4. private static Logger Log=logger.getlogger (helloant.   Class);
  5. public static void Main (string[] args) {
  6. Log.info ("Hello ant!");
  7. }
  8. }

Modify the class output path in Build path to "helloant/classes".

We are right------Select export-->ant buildfile--> the next--and modify the corresponding properties in the project name-->finish




Upon completion we will find a "build.xml" file in the project directory:



After opening is the following code:

XML code
  1. <? XML version= "1.0" encoding="UTF-8" standalone="No"?>
  2. <project basedir="." default="Build" name="helloant">
  3. <property environment="env"/>
  4. <property name= "debuglevel" value="Source,lines,vars"/>
  5. <property name="target" value="1.6"/>
  6. <property name="source" value="1.6"/>
  7. <path id="Helloant.classpath">
  8. <pathelement location="classes"/>
  9. <pathelement location=". /log4j.jar "/>
  10. </path>
  11. <target name="init">
  12. <mkdir dir="classes"/>
  13. <copy includeemptydirs="false" todir="Classes">
  14. <fileset dir="src">
  15. <exclude name="**/*.launch"/>
  16. <exclude name="**/*.java"/>
  17. </fileset>
  18. </copy>
  19. </target>
  20. <target name="clean">
  21. <delete dir="classes"/>
  22. </target>
  23. <target depends="clean" name="Cleanall"/>
  24. <target depends="Build-subprojects,build-project" name="Build"/>
  25. <target name="build-subprojects"/>
  26. <target depends="Init" name="Build-project">
  27. <echo message="${ant.project.name}: ${ant.file}"/>
  28.         <javac < span class= "attribute" >debug= "true"  debuglevel= "${debuglevel}"  destdir= " Classes " includeantruntime=" false " source= "${source}"  target=" ${target} ">  
  29. <src path="src"/>
  30. <classpath refid="Helloant.classpath"/>
  31. </javac>
  32. </target>
  33. <target description="Build all projects which reference this project. Useful to propagate changes. " name="build-refprojects"/>
  34. <target description="copy Eclipse compiler jars to ant lib directory" name=" Init-eclipse-compiler ">
  35. <copy todir="${ant.library.dir}">
  36. <fileset dir="${eclipse_home}/plugins" includes="Org.eclipse.jdt.core_*.jar"/ >
  37. </copy>
  38. <unzip dest="${ant.library.dir}">
  39. <patternset includes="Jdtcompileradapter.jar"/>
  40. <fileset dir="${eclipse_home}/plugins" includes="Org.eclipse.jdt.core_*.jar" />
  41. </Unzip>
  42. </target>
  43. <target description="compile project with Eclipse compiler" name=" Build-eclipse-compiler ">
  44. <property name= "build.compiler" value="Org.eclipse.jdt.core.JDTCompilerAdapter"/ >
  45. <antcall target="Build"/>
  46. </target>
  47. <target name="helloant">
  48. <java classname="com.ant.hello.HelloAnt" failonerror="true" fork="yes" >
  49. <classpath refid="Helloant.classpath"/>
  50. </java>
  51. </target>
  52. </Project>

We can modify the name and the path under the <path> tag according to the situation, of course, this kind of thing compares the method of generation of the Fool, let's change a generation method that can be set in detail below.

Click the navigation Bar "Project"-"Properties"-"builder"-"New"-"Ant Builder":



We can set it in detail according to the given interface.

    • Size: 6.4 KB
    • Size: 8.2 KB
    • Size: Ten KB
    • Size: Ten KB
    • Size: 11.3 KB
    • Size: 9 KB
    • Size: KB

Go Using Ant in Eclipse

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.