编译工具 之 ant
生活随笔
收集整理的這篇文章主要介紹了
编译工具 之 ant
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、概述
??? 需要設置的環境變量:
??? ??? JAVA_HOME="D:\JDK",
??? ??? ANT_HOME="D:\ant",
??? ??? PATH=".,%JAVA_HOME%\bin,%ANT_HOME%bin"
??? 運行:ant -buildfile test.xml -Dbuild=build/classes dist
(含義為:執行test.xml的編譯腳本,參數build的值為build/classes,要執行的target為dist)
??? 默認的編譯腳本為build.xml,默認的target為編譯腳本中的project的default屬性值所對應的target
二、常用task
??? 編譯腳本是xml文檔,元素有project->target->task,property,filter。
(右擊前面查看圖片)
??? task有內置的和可選的之分,可選task需要下載額外的包來支持,此外可以編寫自己的task。
1、Echo????
Examples
??? basedir="${build}/classes"
??? includes="mypackage/test/**"
??? excludes="**/Test.class" />
<jar destfile="${dist}/lib/app.jar">
??? <fileset dir="${build}/classes"
??? ??? ??? excludes="**/Test.class" />
???? <fileset dir="${src}/resources"/>
</jar>
4、javadoc
??? 需要設置的環境變量:
??? ??? JAVA_HOME="D:\JDK",
??? ??? ANT_HOME="D:\ant",
??? ??? PATH=".,%JAVA_HOME%\bin,%ANT_HOME%bin"
??? 運行:ant -buildfile test.xml -Dbuild=build/classes dist
(含義為:執行test.xml的編譯腳本,參數build的值為build/classes,要執行的target為dist)
??? 默認的編譯腳本為build.xml,默認的target為編譯腳本中的project的default屬性值所對應的target
二、常用task
??? 編譯腳本是xml文檔,元素有project->target->task,property,filter。
(右擊前面查看圖片)
??? task有內置的和可選的之分,可選task需要下載額外的包來支持,此外可以編寫自己的task。
1、Echo????
Parameters
| Attribute | Description | Required |
| message | the message to echo. | Yes, unless data is included in a character section within this element. |
| file | the file to write the message to. | No |
| append | Append to an existing file? | No - default is false. |
| level | Control the level at which this message is reported. One of "error", "warning", "info", "verbose", "debug" | No - default is "warning". |
Examples
<echo message="Hello, world"/>
<echo message="Embed a line break:${line.separator}"/>
<echo>Embed another:${line.separator}</echo>
<echo>This is a longer message stretching over
two lines.
</echo>
2、Javac
Parameters(not all)
| Attribute | Description | Required |
| srcdir | Location of the java files. (See the note below.) | Yes, unless nested <src> elements are present. |
| destdir | Location to store the class files. | No |
| includes | Comma- or space-separated list of files (may be specified using wildcard patterns) that must be included; all .java files are included when omitted. | No |
| includesfile | The name of a file that contains a list of files to include (may be specified using wildcard patterns). | No |
| excludes | Comma- or space-separated list of files (may be specified using wildcard patterns) that must be excluded; no files (except default excludes) are excluded when omitted. | No |
| excludesfile | The name of a file that contains a list of files to exclude (may be specified using wildcard patterns). | No |
| classpath | The classpath to use. | No |
| sourcepath | The sourcepath to use; defaults to the value of the srcdir attribute (or nested <src> elements). To suppress the sourcepath switch, use sourcepath="". | No |
Examples
<javac srcdir="${src}"
destdir="${build}"
includes="mypackage/p1/**,mypackage/p2/**"
excludes="mypackage/p1/testpackage/**"
classpath="xyz.jar"
debug="on"
/>
3、jar
Parameters(not all)
| Attribute | Description | Required |
| destfile | the JAR file to create. | Yes |
| basedir | the directory from which to jar the files. | No |
| compress | Not only store data but also compress them, defaults to true. Unless you set the keepcompression attribute to false, this will apply to the entire archive, not only the files you've added while updating. | No |
| keepcompression | For entries coming from existing archives (like nested zipfilesets or while updating the archive), keep the compression as it has been originally instead of using the compress attribute. Defaults false. Since Ant 1.6 | No |
| encoding | The character encoding to use for filenames inside the archive. Defaults to UTF8. It is not recommended to change this value as the created archive will most likely be unreadable for Java otherwise. | No |
| filesonly | Store only file entries, defaults to false | No |
| includes | comma- or space-separated list of patterns of files that must be included. All files are included when omitted. | No |
| includesfile | the name of a file. Each line of this file is taken to be an include pattern | No |
| excludes | comma- or space-separated list of patterns of files that must be excluded. No files (except default excludes) are excluded when omitted. | No |
| excludesfile | the name of a file. Each line of this file is taken to be an exclude pattern | No |
| defaultexcludes | indicates whether default excludes should be used or not ("yes"/"no"). Default excludes are used when omitted. | No |
| manifest | the manifest file to use. This can be either the location of a manifest, or the name of a jar added through a fileset. If its the name of an added jar, the task expects the manifest to be in the jar at META-INF/MANIFEST.MF | No |
Examples
<jar destfile="${dist}/lib/app.jar"??? basedir="${build}/classes"
??? includes="mypackage/test/**"
??? excludes="**/Test.class" />
<jar destfile="${dist}/lib/app.jar">
??? <fileset dir="${build}/classes"
??? ??? ??? excludes="**/Test.class" />
???? <fileset dir="${src}/resources"/>
</jar>
4、javadoc
Parameters(not all)
| Attribute | Description | Availability | Required |
| sourcepath | Specify where to find source files | all | At least one of the three or nested <sourcepath>, <fileset> or <packageset> |
| sourcepathref | Specify where to find source files by reference to a PATH defined elsewhere. | all | |
| sourcefiles | Comma separated list of source files -- see also the nested source element. | all | |
| destdir | Destination directory for output files | all | Yes, unless a doclet has been specified. |
| maxmemory | Max amount of memory to allocate to the javadoc VM | all | No |
| packagenames | Comma separated list of package files (with terminating wildcard) -- see also the nested package element. | all | No |
| packageList | The name of a file containing the packages to process | 1.2+ | No |
| classpath | Specify where to find user class files | all | No |
Example
<javadoc packagenames="com.dummy.test.*"
sourcepath="src"
excludepackagenames="com.dummy.test.doc-files.*"
defaultexcludes="yes"
destdir="docs/api"
author="true"
version="true"
use="true"
windowtitle="Test API">
<doctitle><![CDATA[<h1>Test</h1>]]></doctitle>
<bottom><![CDATA[<i>Copyright © 2000 Dummy Corp. All Rights Reserved.</i>]]></bottom>
<tag name="todo" scope="all" description="To do:" />
<group title="Group 1 Packages" packages="com.dummy.test.a*"/>
<group title="Group 2 Packages" packages="com.dummy.test.b*:com.dummy.test.c*"/>
<link offline="true" href="http://java.sun.com/products/jdk/1.2/docs/api/" packagelistLoc="C:\tmp"/>
<link href="http://developer.java.sun.com/developer/products/xml/docs/api/"/>
</javadoc>
轉載于:https://www.cnblogs.com/menghe/articles/98020.html
總結
以上是生活随笔為你收集整理的编译工具 之 ant的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求一个好听好记的汽修厂名字
- 下一篇: 公积金每月交多少钱啊?