zoukankan      html  css  js  c++  java
  • ant编译java的例子

    ant hello world
    建一上文件夹HelloWorld.里面的内容如下所示:

    第一个例子不讨论build1.xml和HelloWorld1.java.运行出helloworld程序要如下步骤:
    1.建一个文件夹,用于保存编译成的.class
    2.编译.java文件,生成.class文件
    3.运行程序,出结果
    第1步通过下面代码实现

    <target name="init" depends="clean" description="Removes the temporary directories used">
        <mkdir dir="out/classes" />
    </target>
    

    第2步通过下面代码实现

    <target name="compile" depends="init" description="Compiles the source code">
            <javac srcdir=".src" destdir="out/classes" includeantruntime="false"/>
            <echo>compilation complete!</echo>
        </target>
    

    第3步通过下面代码实现.

    <target name="execute" depends="compile">
            <java
                    classname="edu.cgxy.helloworld.HelloWorld"
                    classpath="out/classes">
            </java>
    </target>
    

    build.xml的完整例子如下:

    <?xml version="1.0"?>
    <project name="HelloWorld" default="execute" >
        <description>Compiles and runs a simple program</description>
        <target name="init" depends="clean" description="Removes the temporary directories used">
            <mkdir dir="out/classes" />
        </target>
        <target name="compile" depends="init" description="Compiles the source code">
            <javac srcdir=".src" destdir="out/classes" includeantruntime="false"/>
            <echo>compilation complete!</echo>
        </target>
        <target name="clean">
            <delete dir="out" />
        </target>
        <target name="execute" depends="compile">
            <java
                    classname="edu.cgxy.helloworld.HelloWorld"
                    classpath="out/classes">
            </java>
        </target>
    </project>
    

    执行命令ant -f build1.xml可以运行结果. 还有一个名字为clean的target上面没有介绍.作用是运行程序之后先把以前的结果删除.
    程序源代码: https://github.com/zhouyang209117/AntTutorial/tree/master/HelloWorld

  • 相关阅读:
    数组过滤
    数组过滤
    以文件流的形式下载文件
    antD 时间年的写法
    如何判断一个js对象是否是Array,
    webSocket 使用
    react map循环的dom,点击让当前数组里的isShow显示false
    react react-draft-wysiwyg使用
    jQuery placeholder插件 让IE也能够支持placeholder属性
    JavaScript 逼真图片倒计时实现代码 js时间图片倒计时
  • 原文地址:https://www.cnblogs.com/zhouyang209117/p/5411046.html
Copyright © 2011-2022 走看看