使用ant编译helloworld.java的实例

1.新建一个ant 项目目录结构: 
  /home/nh/helloworld   :项目主目录 
              /src   :源程序目录 
              /classes   :编译后的   class   文件目录 
              /lib   :开发项目所需要的类库目录,比如开发数据库时所需要的   jdbc   lib(这次没用到) 
              /jar   :打包好的   jar   程序目录(这次没用到) 
              /build.xml   :项目配置文件 

build.xml内容如下:  

<?xml version="1.0" encoding="UTF-8" ?>



<project default="build" basedir=".">
   
    <property name="appname" value="helloworld" />
    <property name="base" value="." />
    <property name="src" value="src" />
    <property name="build" value="classes" />
    <property name="myclasspath" value="${build}" />
   




    <target name="build">
           <mkdir dir="${build}" />
           <javac classpath="$myclasspath" srcdir="${src}" destdir="${build}">
                 <include name="helloworld.java" />
           </javac>
    </target>




   <target name="run" depends="build">
       <exec executable="java">
          <arg line=" -classpath ${myclasspath} helloworld" />
       </exec>
   </target>




   <target name="clean">
       <delete includeEmptyDirs="true">
           <fileset dir="${build}"/>
       </delete>
   </target>

</project>



2.创建   helloworld.java 

/home/nh/helloword/src/helloworld.java ,源码如下:
----------------------------------------------------------------------------- 
/** 
*   Demo   class   for   run   HelloWorld   by   ANT 
*/ 

public   class   HelloWorld   { 
      public   static   void   main(String   args[]){ 
              System.out.println   ( "Hello   World! "); 
      } 
}   //EOC 
----------------------------------------------------------------------------- 

3.编译   helloworld .java
nh@57ubuntu:~/helloworld$ ant build
Buildfile: build.xml
build:
    [javac] Compiling 1 source file to /home/nh/helloworld/classes
BUILD SUCCESSFUL
Total time: 1 second

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值