Eclipse下使用Ant

目前的Eclipse都集成了ant,本文图示如何在eclipse下使用ant。
1.新建Java Project-新建Java文件HelloWorld.java
HelloWorld.java
package  example;
public   class  HelloWorld {
     public   static   void  main(String[] args) {
       System. out .println( "Hello World" );
    }
}
 
2.在工程根目录下新建build.xml
build.xml
<?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>
此脚本文件内容是编译/src/example下的java文件,并就地生成class文件,将这个class文件打成jar包,HelloWorld.jar。
此时工程的目录结构如下图所示:
右键选中HelloAnt工程,选择Properties:
选择Builders-New…,选择Ant Build,
Name:Ant_Builder;
Buildfile:${workspace_loc:/HelloAnt/build.xml};
Base Directory:${workspace_loc:/HelloAnt};
(按“Browse Workspace”选择工程根目录)
在Builder面板中钩上Ant_Build,去掉Java Builder,即可编译执行。
每次编译时,右键build.xml,选择Run As-Ant Build:
此示例工程编译结果:
Buildfile:  D:\dev\Workspaces\J2EE\HelloAnt\build.xml
compile :
compress :
main :
     [ echo ] Building the .jar file.
BUILD SUCCESSFUL
Total time: 281 milliseconds
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值