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
- Package Com.ant.hello;
- Import Org.apache.log4j.Logger;
- Public class Helloant {
- private static Logger Log=logger.getlogger (helloant. Class);
- public static void Main (string[] args) {
- Log.info ("Hello ant!");
- }
- }
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
- <? XML version= "1.0" encoding="UTF-8" standalone="No"?>
- <project basedir="." default="Build" name="helloant">
- <property environment="env"/>
- <property name= "debuglevel" value="Source,lines,vars"/>
- <property name="target" value="1.6"/>
- <property name="source" value="1.6"/>
- <path id="Helloant.classpath">
- <pathelement location="classes"/>
- <pathelement location=". /log4j.jar "/>
- </path>
- <target name="init">
- <mkdir dir="classes"/>
- <copy includeemptydirs="false" todir="Classes">
- <fileset dir="src">
- <exclude name="**/*.launch"/>
- <exclude name="**/*.java"/>
- </fileset>
- </copy>
- </target>
- <target name="clean">
- <delete dir="classes"/>
- </target>
- <target depends="clean" name="Cleanall"/>
- <target depends="Build-subprojects,build-project" name="Build"/>
- <target name="build-subprojects"/>
- <target depends="Init" name="Build-project">
- <echo message="${ant.project.name}: ${ant.file}"/>
- <javac < span class= "attribute" >debug= "true" debuglevel= "${debuglevel}" destdir= " Classes " includeantruntime=" false " source= "${source}" target=" ${target} ">
- <src path="src"/>
- <classpath refid="Helloant.classpath"/>
- </javac>
- </target>
- <target description="Build all projects which reference this project. Useful to propagate changes. " name="build-refprojects"/>
- <target description="copy Eclipse compiler jars to ant lib directory" name=" Init-eclipse-compiler ">
- <copy todir="${ant.library.dir}">
- <fileset dir="${eclipse_home}/plugins" includes="Org.eclipse.jdt.core_*.jar"/ >
- </copy>
- <unzip dest="${ant.library.dir}">
- <patternset includes="Jdtcompileradapter.jar"/>
- <fileset dir="${eclipse_home}/plugins" includes="Org.eclipse.jdt.core_*.jar" />
- </Unzip>
- </target>
- <target description="compile project with Eclipse compiler" name=" Build-eclipse-compiler ">
- <property name= "build.compiler" value="Org.eclipse.jdt.core.JDTCompilerAdapter"/ >
- <antcall target="Build"/>
- </target>
- <target name="helloant">
- <java classname="com.ant.hello.HelloAnt" failonerror="true" fork="yes" >
- <classpath refid="Helloant.classpath"/>
- </java>
- </target>
- </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.
Go Using Ant in Eclipse