build.xml文档模板

来源:互联网 发布:网络通信协议规格说明 编辑:程序博客网 时间:2024/05/18 00:34

ant的使用:

系统环境变量中设置: 

path: 加上:D:\apache-ant-1.7\bin 

新建ANT_HOME:D:\apache-ant-1.7 

3.在cmd命令中:输入ant,如果输出: 

Buildfile:build.xml does not exist! 

Build failed 

说明ant安装成功。 



build.xml 配置文档模板: 用的时候可以直接拿来做一个模板

<?xml version="1.0" encoding="UTF-8"?> 

<project name="Hello world" default="doc"> 



<!-- properies --> 

<property name="src.dir" value="WEB-INF/src" /> 

<property name="report.dir" value="report" /> 

<property name="classes.dir" value="WEB-INF/classes" /> 

<property name="lib.dir" value="WEB-INF/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}" destdir="${classes.dir}" target="6.0"> 

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



</fail> 

</target> 



<!-- 打包成jar --> 

<target name="jar" 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> 



<!-- 将项目打包成war--> 

<target name="war" depends="jar"> 

<war destfile="${basedir}/myApp.war" webxml="${basedir}/WEB-INF/web.xml"> 

<!--包含文件夹下所有内容--> 

<fileset dir="${basedir}" casesensitive="yes" id="id"> 

<include name="WEB-INF/**" /> 

<exclude name="*.war" /> 

</fileset> 

<lib dir="${lib.dir}"> 

<include name="*.jar"/> 

</lib> 



</war> 

</target> 



<!-- 输出api文档 --> 

<target name="doc" depends="jar" 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> 



错误列表解释: 

compile错误:E:\it502\build.xml:37: Error starting modern compiler 

JRE:工程的JRE在右键→properties→java compiler→即可设置JRE的版本。 

是因为eclipse的JRE和jdk不一致, 

保持系统运行eclipse的jre和jdk(java_home里面提供的)的一致就可以了