熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Ant的配置使用入門

2022-06-13   來源: Java開源技術 

  下載安裝下載

  需要設置的環境變量

  ANT_HOMEant的安裝目錄

  JAVA_HOMEjdk的安裝目錄

  PATH把%ANT_HOME%\bin目錄加到path變量以便於從命令行下直接運行ant

  假定ant解壓在c\ant   jdk裝d\jsdk

  則在命令行下執行以下命令

   set ANT_HOME=c:\ant
set JAVA_HOME=D:\jsdk
set PATH=%PATH%;c:\ant\bin

  工程文件目錄結構

  一個ant 工程目錄結構

  C\workspace\anttest工程主目錄

  \src 源程序目錄

  \build\classes 編譯後的 class 文件目錄

  \lib 開發工程所需要的類庫目錄比如開發數據庫時所需要的 jdbc lib(這次沒用到)

  \jar 打包好的 jar 程序目錄(這次沒用到)

  \buildxml 工程配置文件\buildpropertiees工程資源文件

  建立工程描述文件和建立工程資源文件

  建立工程描述文件buildxml

   <?xml version=?>

<project default=main basedir=>

    <echo message=pulling in property files />
    <property file=buildproperties />

    <target name=init>
        <echo message=init delete the old class files and create the new folds />
        <delete dir=${classpath} />
        <mkdir dir=${classpath} />
    </target>

    <target name=compile depends=init>
        <echo message=compile the java source files />
        <javac srcdir=src\hello\ant destdir=${classpath} />
    </target>

    <target name=main depends=compile>
        <echo message=calling java to run this java project />
        <java classname=helloantHelloAnt>
            <classpath>
                <pathelement path=${classpath} />
            </classpath>
        </java>
    </target>

</project>

  建立工程資源文件buildproperties

  文件內容是下面一行內容

  

  classpath=build\\classes

  建立java源文件helloantHelloAntjava

  

  package helloant;

public class HelloAnt {
    public static void main(String[] args) {
        Systemoutprintln(hello ant the first time using ant it is great);
    }
}

  編譯

   C:\workspace\anttest>ant buildfile buildxml
Buildfile: buildxml
     [echo] pulling in property files

init:
     [echo] init delete the old class files and create the new folds
   [delete] Deleting directory C:\workspace\anttest\build\classes
    [mkdir] Created dir: C:\workspace\anttest\build\classes

compile:
     [echo] compile the java source files
    [javac] Compiling source file to C:\workspace\anttest\build\classes

main:
     [echo] calling java to run this java project
     [java] hello ant the first time using ant it is great

BUILD SUCCESSFUL
Total time: milliseconds

C:\workspace\anttest>


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28515.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.