
- Apache ANT 教程
- ANT - 主頁
- ANT - 簡介
- ANT - 設定環境
- ANT - 構建檔案
- ANT - Property 任務
- ANT - 屬性檔案
- ANT - 資料型別
- ANT - 構建專案
- ANT - 構建文件
- ANT - 建立 JAR 檔案
- ANT - 建立 WAR 檔案
- ANT - 打包應用程式
- ANT - 部署應用程式
- ANT - 執行 Java 程式碼
- ANT - Eclipse 整合
- ANT - JUnit 整合
- ANT - 擴充套件 Ant
- Apache ANT 的有用示例
- ANT - 使用 Token
- ANT - 使用命令列引數
- ANT - 使用 If Else 引數
- ANT - 自定義元件
- ANT - 偵聽器和記錄器
- Apache ANT 資源
- ANT - 快速指南
- ANT - 有用資源
- ANT - 討論
Ant - 使用命令列引數
Ant 能輕鬆讀取命令列引數,以便將其資料傳遞給其任務。
命令列引數選項
ant [options] [target [target2 [target3] ...]] Options: -help, -h print this message and exit -projecthelp, -p print project help information and exit -version print the version information and exit -diagnostics print information that might be helpful to diagnose or report problems and exit -quiet, -q be extra quiet -silent, -S print nothing but task outputs and build failures -verbose, -v be extra verbose -debug, -d print debugging information -emacs, -e produce logging information without adornments -lib <path> specifies a path to search for jars and classes -logfile <file> use given file for log -l <file> '' -logger <classname> the class which is to perform logging -listener <classname> add an instance of class as a project listener -noinput do not allow interactive input -buildfile <file> use given buildfile -file <file> '' -f <file> '' -D <property>=<value> use value for given property -keep-going, -k execute all targets that do not depend on failed target(s) -propertyfile <name> load all properties from file with -D properties taking precedence -inputhandler <class> the class which will handle input requests -find <file> (s)earch for buildfile towards the root of -s <file> the filesystem and use it -nice number A niceness value for the main thread:1 (lowest) to 10 (highest); 5 is the default -nouserlib Run ant without using the jar files from ${user.home}/.ant/lib -noclasspath Run ant without using CLASSPATH -autoproxy Java 5+ : use the OS proxies -main <class> override Ant's normal entry point
我們將使用 -Dproperty 將變數傳遞給 build 任務。
示例
使用具有以下內容的 text1.txt 檔案建立一個 src 資料夾 −
This is a sample text written in 2021.
使用以下內容建立 build.xml −
<?xml version="1.0"?> <project name="sample" basedir="." default="copy"> <target name="copy"> <copy todir="${dest.dir}" filtering="true"> <fileset dir="${src.dir}"/> </copy> </target> </project>
輸出
此處,我們正在使用 src.dir 和 dest.dir 屬性,而無需定義它們。我們將使用命令列引數傳遞它們。在上述構建檔案中執行 Ant 會產生以下輸出 −
F:\tutorialspoint\ant>ant -Dsrc.dir=src -Ddest.dir=build Buildfile: F:\tutorialspoint\ant\build.xml copy: [copy] Copying 1 file to F:\tutorialspoint\ant\build BUILD SUCCESSFUL Total time: 0 seconds F:\tutorialspoint\ant>
驗證已複製的檔案的內容到構建資料夾。
This is a sample text written in 2021.
廣告