(转)Eclipse中使用Ant
http://286.iteye.com/blog/1909223
Eclipse中已经集成了Ant,我们可以直接在Eclipse中运行Ant,这里我要做的不是直接运行已编写好的build.xml文件,而是利用Ant插件来生成一个构建文件。
首先打开Eclipse,点击导航栏的"Window"-->"Preferences"-->"Ant"

其中有Ant的代码模板,格式化,classpath等属性设置,可以根据具体情况自行设置,都比较简单。
我们要构建一个有依赖jar包项目的构建文件,这里我拿log4j为例,将log4j添加到HelloAnt项目的build path当中,如图所示:

修改HelloAnt.java的源代码为:
- 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!");
- }
- }
修改build path中的class输出路径为"HelloAnt/classes"。
我们在项目名称上右键-->选择Export(导出)-->Ant Buildfile-->下一步-->修改相应属性-->Finish


完成之后我们会发现项目目录里多了一个"build.xml"文件:

打开之后是如下代码:
- <?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 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>
我们可以根据情况修改其中的<path>标签下的命名及路径,当然这种事比较傻瓜式的生成方法,下面我们换一种可以详细设置的生成方法。
点击导航栏"Project"-->"Properties"-->"Builder"-->"New"-->"Ant Builder":

根据给出的界面我们可以详细设置。

- 大小: 6.4 KB

- 大小: 8.2 KB

- 大小: 10 KB

- 大小: 10 KB

- 大小: 11.3 KB

- 大小: 9 KB

- 大小: 41 KB
(转)Eclipse中使用Ant的更多相关文章
- 在Eclipse中集成Ant配置
提要:本文将向你展示如何使用Eclipse设置为Ant所用的属性值和环境变量,并简要分析如何配置Ant编辑器以便从Eclipse内部操作Ant文件. 一. 修改Ant Classpath 在使用一个可 ...
- Ant学习笔记(2) 在Eclipse中使用Ant
Eclipse默认提供了对Ant的支持,在Eclipse中不需要安装任何插件就能直接编辑和运行Ant.Eclipse中包含了一个Ant脚本编辑器,Ant脚本编辑器提供了对Ant脚本的语法搞来高亮.自动 ...
- Eclipse中集成Ant配置 (转)
目前的Eclipse都集成了ant,本文图示如何在eclipse下使用ant. 1.新建Java Project-新建Java文件HelloWorld.java HelloWorld.java pac ...
- Eclipse中执行Ant脚本出现Could not find the main class的问题及解
试过了:https://blog.csdn.net/bookroader/article/details/2300337 但是不管用,偶然看到这篇没有直接关系的 https://blog.csdn.n ...
- Eclipse中Ant的配置与测试 转
欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jiangxinnju/p/4781259.html GitHub地址: https://github.com/ji ...
- Eclipse中Ant的配置与测试
在Eclipse中使用Ant Ant是Java平台下非常棒的批处理命令执行程序,能非常方便地自动完成编译,测试,打包,部署等等一系列任务,大大提高开发效率.如果你现在还没有开始使用Ant,那就要赶快开 ...
- 在Android开发中使用Ant 一:环境的搭建及入门
配置Ant环境 下载Ant:http://ant.apache.org/bindownload.cgi 在windows上应该选择zip压缩包,将zip压缩包解压到一个目录. 打开系统环境变量,在系统 ...
- Eclipse正在使用Ant扑灭Android数据包错误的解决方案 – Perhaps JAVA_HOME does not point to the JDK
问题描写叙述: 在Eclipse中执行ant批量打包工具出错,日志信息例如以下: D:\Android\android-sdk-windows\tools\ant\build.xml:601: The ...
- eclipse juno版本中没用 ant
下载了谷歌提供的Android集成开发工具ADT,里面封装了Eclipse,但是很奇怪的是竟然没有Ant插件在里面 标准的Eclipse一般都是内置集成了Ant的. 然后到eclipse的plugin ...
随机推荐
- Balancing Symbols
symbols匹配问题 #include<iostream> #include<string> using namespace std; struct Node { char ...
- centos装openoffice
一.安装openOffice1.使用tar -xzvf OOo_3.2.0_LinuxIntel_install_wJRE_en-US.tar.gz解压缩后,会得到OOO320_m12_native_ ...
- Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html"
2015-11-16 10:39:17.235 PullDemo[338:60b] Application windows are expected to have a root view contr ...
- Linux Ubuntu 内核升级
方法一 : 1 更新系统源 apt-get update 2 搜索内核文件 apt-cache search linux-image 3 安装 apt-get install -y linux-im ...
- 解读QML之一
http://cache.baiducontent.com/c?m=9d78d513d98002b8599dcb201a17a7374408c6347691c4523f8a9c12d522195646 ...
- jsp 页面取值
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- jQuery实现DIV拖动
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 为什么要在onNewIntent的时候要显示的去调用setIntent
一.原因: 当调用到onNewIntent(intent)的时候,需要在onNewIntent() 中使用setIntent(intent)赋值给Activity的Intent.否则,后续的getIn ...
- java操作oracle的blob,clob数据
一.区别和定义 LONG: 可变长的字符串数据,最长2G,LONG具有VARCHAR2列的特性,可以存储长文本一个表中最多一个LONG列 LONG RAW: 可变长二进制数据,最长2G CLOB: ...
- 【搜索 回溯】 zoj 1002
题意:一些机枪彼此不能在同一行和同一列,但是由于有墙的阻隔,能保证子弹无法穿透,即可以同行同列,现问如果说给了一个n*n(n<=4)的矩阵,并给出了墙的分布情况,能否求出最大能繁殖的机枪数. 思 ...