日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Eclipse之ANT使用

發(fā)布時間:2023/12/19 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Eclipse之ANT使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Ant是Java平臺下非常棒的批處理命令執(zhí)行程序,能非常方便地自動完成編譯,測試,打包,部署等等一系列任務(wù),大大提高開發(fā)效率。如果你現(xiàn)在還沒有開始使用Ant,那就要趕快開始學(xué)習(xí)使用,使自己的開發(fā)水平上一個新臺階。

  Eclipse中已經(jīng)集成了Ant,我們可以直接在Eclipse中運行Ant。

  以前面建立的Hello工程為例,創(chuàng)建以下目錄結(jié)構(gòu):


  新建一個build.xml,放在工程根目錄下。build.xml定義了Ant要執(zhí)行的批處理命令。雖然Ant也可以使用其它文件名,但是遵循標(biāo)準(zhǔn)能更使開發(fā)更規(guī)范,同時易于與別人交流。

  通常,src存放Java源文件,classes存放編譯后的class文件,lib存放編譯和運行用到的所有jar文件,web存放JSP等web文件,dist存放打包后的jar文件,doc存放API文檔。

  然后在根目錄下創(chuàng)建build.xml文件,輸入以下內(nèi)容:

<?xml version="1.0"?>
<project name="Hello world" default="doc">

<!-- properies -->
<property name="src.dir" value="src" />
<property name="report.dir" value="report" />
<property name="classes.dir" value="classes" />
<property name="lib.dir" value="lib" />
<property name="dist.dir" value="dist" />
<property name="doc.dir" value="doc"/>

<!-- 定義classpath -->
<path id="master-classpath">
<fileset file="${lib.dir}/*.jar" />
<pathelement path="${classes.dir}"/>
</path>

<!-- 初始化任務(wù) -->
<target name="init">
</target>

<!-- 編譯 -->
<target name="compile" depends="init" description="compile the source files">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" target="1.4">
<classpath refid="master-classpath"/>
</javac>
</target>

<!-- 測試 -->
<target name="test" depends="compile" description="run junit test">
<mkdir dir="${report.dir}"/>
<junit printsummary="on"
haltonfailure="false"
failureproperty="tests.failed"
showoutput="true">
<classpath refid="master-classpath" />
<formatter type="plain"/>
<batchtest todir="${report.dir}">
<fileset dir="${classes.dir}">
<include name="**/*Test.*"/>
</fileset>
</batchtest>
</junit>
<fail if="tests.failed">
***********************************************************
**** One or more tests failed! Check the output ... ****
***********************************************************
</fail>
</target>

<!-- 打包成jar -->
<target name="pack" depends="test" description="make .jar file">
<mkdir dir="${dist.dir}" />
<jar destfile="${dist.dir}/hello.jar" basedir="${classes.dir}">
<exclude name="**/*Test.*" />
<exclude name="**/Test*.*" />
</jar>
</target>

<!-- 輸出api文檔 -->
<target name="doc" depends="pack" description="create api doc">
<mkdir dir="${doc.dir}" />
<javadoc destdir="${doc.dir}"
author="true"
version="true"
use="true"
windowtitle="Test API">
<packageset dir="${src.dir}" defaultexcludes="yes">
<include name="example/**" />
</packageset>
<doctitle><![CDATA[<h1>Hello, test</h1>]]></doctitle>
<bottom><![CDATA[<i>All Rights Reserved.</i>]]></bottom>
<tag name="todo" scope="all" description="To do:" />
</javadoc>
</target>
</project>


  以上xml依次定義了init(初始化),compile(編譯),test(測試),doc(生成文檔),pack(打包)任務(wù),可以作為模板。

  選中Hello工程,然后選擇“Project”,“Properties”,“Builders”,“New…”,選擇“Ant Build”:


  填入Name:Ant_Builder;Buildfile:build.xml;Base Directory:${workspace_loc:/Hello}(按“Browse Workspace”選擇工程根目錄),由于用到了junit.jar包,搜索Eclipse目錄,找到j(luò)unit.jar,把它復(fù)制到 Hello/lib目錄下,并添加到Ant的Classpath中:


  然后在Builder面板中鉤上Ant_Build,去掉Java Builder:


  再次編譯,即可在控制臺看到Ant的輸出:

Buildfile: F:\eclipse-projects\Hello\build.xml

init:

compile:
[mkdir] Created dir: F:\eclipse-projects\Hello\classes
[javac] Compiling 2 source files to F:\eclipse-projects\Hello\classes

test:
[mkdir] Created dir: F:\eclipse-projects\Hello\report
[junit] Running example.HelloTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.02 sec

pack:
[mkdir] Created dir: F:\eclipse-projects\Hello\dist
[jar] Building jar: F:\eclipse-projects\Hello\dist\hello.jar

doc:
[mkdir] Created dir: F:\eclipse-projects\Hello\doc
[javadoc] Generating Javadoc
[javadoc] Javadoc execution
[javadoc] Loading source files for package example...
[javadoc] Constructing Javadoc information...
[javadoc] Standard Doclet version 1.4.2_04
[javadoc] Building tree for all the packages and classes...
[javadoc] Building index for all the packages and classes...
[javadoc] Building index for all classes...
[javadoc] Generating F:\eclipse-projects\Hello\doc\stylesheet.css...
[javadoc] Note: Custom tags that could override future standard tags: @todo. To avoid potential overrides, use at least one period character (.) in custom tag names.
[javadoc] Note: Custom tags that were not seen: @todo
BUILD SUCCESSFUL
Total time: 11 seconds


  Ant依次執(zhí)行初始化,編譯,測試,打包,生成API文檔一系列任務(wù),極大地提高了開發(fā)效率。將來開發(fā)J2EE項目時,還可加入部署等任務(wù)。并且,即使脫離了Eclipse環(huán)境,只要正確安裝了Ant,配置好環(huán)境變量ANT_HOME=<Ant解壓目錄>,Path=…;%ANT_HOME%\bin,在命令行提示符下切換到Hello目錄,簡單地鍵入ant即可

from http://blog.163.com/abc.zxj-001/blog/static/25693412010101611444230/


Ant 設(shè)置編譯源文件編碼

<target name="compile">

?<mkdir dir="${classes.dir}" />

?<javac encoding="UTF-8" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="project.class.path" />

</target>


轉(zhuǎn)載于:https://blog.51cto.com/tengluoyue/1346765

總結(jié)

以上是生活随笔為你收集整理的Eclipse之ANT使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。