码迷,mamicode.com
首页 > 系统相关 > 详细

在Eclipse下使用ant

时间:2014-07-13 20:24:57      阅读:359      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   java   color   

目前的Eclipse都集成了ant,但是如何在Eclipse下使用ant呢?

1.新建Java Project-新建Java文件HelloWorld.java

HelloWorld.java:

bubuko.com,布布扣
package example;
public class HelloWorld {
    public static void main(String[] args) {
       System.out.println("Hello World");
    }
}
View Code

2.在工程根目录下新建build.xml

build.xml:

bubuko.com,布布扣
<?xml version="1.0" encoding="utf-8"?>
<project default="main" basedir=".">
    <target name="main" depends="compile, compress" description="Main target">
       <echo>Building the .jar file.</echo>
    </target>
    <target name="compile" description="Compilation target">
       <javac srcdir="${basedir}/src/example" />
    </target>
    <target name="compress" description="Compression target">
       <jar jarfile="HelloWorld.jar" basedir="${basedir}/src/example"includes="*.class" />
    </target>
</project>
View Code

此脚本文件内容是编译/src/example下的java文件,并就地生成class文件,将这个class文件打成jar包,HelloWorld.jar。

此时工程的目录结构如下图所示:

bubuko.com,布布扣

右键选中HelloAnt工程,选择Properties:

bubuko.com,布布扣

选择Builders-New…,选择Ant Build,

Name:Ant_Builder;

Buildfile:${workspace_loc:/HelloAnt/build.xml};

Base Directory:${workspace_loc:/HelloAnt};

(按“Browse Workspace”选择工程根目录)

 bubuko.com,布布扣

在Builder面板中钩上Ant_Build,去掉Java Builder,即可编译执行。

每次编译时,右键build.xml,选择Run As-Ant Build:

bubuko.com,布布扣

bubuko.com,布布扣

编译结果:

bubuko.com,布布扣
Buildfile: F:\workfile\ant_test\build.xml
compile:
    [javac] F:\workfile\ant_test\build.xml:7: warning: includeantruntime was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
compress:
main:
     [echo] Building the .jar file.
BUILD SUCCESSFUL
Total time: 1 second
View Code

在Eclipse下使用ant,布布扣,bubuko.com

在Eclipse下使用ant

标签:des   style   blog   http   java   color   

原文地址:http://www.cnblogs.com/super-d2/p/3840948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!