(转)Eclipse中使用Ant
2015-11-12 19:09
513 查看
Eclipse中使用Ant
分类: JAVA 工具 服务器2014-08-05 09:59 5507人阅读 评论(0) 收藏 举报anteclipse
/article/4027002.html
Eclipse中已经集成了Ant,我们可以直接在Eclipse中运行Ant,这里我要做的不是直接运行已编写好的build.xml文件,而是利用Ant插件来生成一个构建文件。
首先打开Eclipse,点击导航栏的"Window"-->"Preferences"-->"Ant"
其中有Ant的代码模板,格式化,classpath等属性设置,可以根据具体情况自行设置,都比较简单。
我们要构建一个有依赖jar包项目的构建文件,这里我拿log4j为例,将log4j添加到HelloAnt项目的build path当中,如图所示:
修改HelloAnt.java的源代码为:
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代码
<?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":
根据给出的界面我们可以详细设置。
相关文章推荐
- java泛型(二)--泛型的擦除
- java timer缺陷
- myeclipse自动生成hibernate映射文件的过程
- Spring 4.x框架中的新特性---4.1中的新功能和提升
- Java 自定义注解及利用反射读取注解
- Java匿名内部类
- java初学第一天之:安装及记事本编程
- (java)Reverse Linked List
- Spring对JDBC的支持 Jdbc Template模板类
- (java)Majority Element
- 配置Java Web中文乱码的过滤器
- eclipse 同一个package 有的文件 中文乱码,有的文件中文正常
- Struts2 学习系列 (3) 跳转类型与通配符映射
- (java)leetcode Number of 1 Bits
- loadrunner之java协议脚本编写
- Google Java编程风格指南
- 数组和List之间的转换
- Jmeter插件——Java实现thrift客户端
- POJ 2081 JAVA
- Gson出现javaBean在打包后无效的问题