快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

澳门新葡亰城官网app:Eclipse快速上手指南之使用ANT



Ant是Java平台下异常棒的批处置惩罚敕令履行法度榜样,能异常方便地自动完成编译,测试,打包,支配等等一系列义务,大年夜大年夜前进开拓效率。假如你现在还没有开始应用Ant,那就要从速开始进修应用,使自己的开拓水平上一个新台阶。

Eclipse中已经集成了Ant,我们可以直接在Eclipse中运行Ant。

曩昔面建立的Hello工程为例,创建以下目录布局:

新建一个build.xml,放在工程根目录下。buil澳门新葡亰城官网appd.xml定义了Ant要履行的批处置惩罚敕令。虽然Ant也可以应用其它文件名,然则遵照标准能更使开拓更规范,同时易于与别人交流。

平日,src寄放Java源文件,classes寄放编译后的class文件,lib寄放编译和运行用到的所有jar文件,web寄放JSP等web文件,dist寄放打包后的jar文件,doc寄放API文档。

然后在根目录下创建build.xml文件,输入以下内容:

<?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>

<!-- 初始化义务 -->

<target name="init">

</target>

<!-- 编译 -->

<target name="compile" depends="init" description="compile the source files">

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

<javac srcdir="${src.dir}" 澳门新葡亰城官网appdestdir="${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 澳门新葡亰城官网appapi 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(打包)义务,可以作为模板。

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

填入Name:Ant_Builder;Buildfile:build.xml;Base Directory:${workspace_loc:/Hello}(按&l澳门新葡亰城官网appdquo;Browse Workspace”选择工程根目录),因为用到了junit.jar包,搜索Eclipse目录,找到junit.jar,把它复制到Hello/lib目录下,并添加到Ant的Classpath中:

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

再次编译,即可在节制台看到Ant的输出:

Buildfile: F:eclipse-projectsHellouild.xml

init:

compile:

[mkdir] Created dir: F:eclipse-projectsHelloclasses

[javac] Compiling 2 source files to F:eclipse-projectsHelloclasses

test:

[mkdir] Created dir: F:eclipse-projectsHello

eport

[junit] Running example.HelloTest

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.02 sec

pack:

[mkdir] Created dir: F:eclipse-projectsHellodist

[jar] Building jar: F:eclipse-projectsHellodisthello.jar

doc:

[mkdir] Created dir: F:eclipse-projectsHellodoc

[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-projectsHellodocstylesheet.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依次履行初始化,编译,测试,打包,天生API文档一系列义务,极大年夜地前进了开拓效率。将来开拓J2EE项目时,还可加入支配等义务。并且,纵然离开了Eclipse情况,只要精确安装了Ant,设置设置设备摆设摆设好情况变量ANT_HOME=<Ant解压目录>,Path=…;%ANT_HOME%in,在敕令行提示符下切换到Hello目录,简单地键入澳门新葡亰城官网appant即可。

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

您可能还会对下面的文章感兴趣: