Ant

caitianxiwo 2011-12-14 09:14:56
<?xml version="1.0"?>
<project name="ITHelpSystem" 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="WebContent/WEB-INF/lib"/>
<property name="dist.dir" value="dist"/>
<property name="doc.dir" value="doc"/>
<!-- init classpath-->
<path id = "master-classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${classes.dir}"/>
</path>
<!-- init -->
<target name="init"></target>
<!--compile-->
<target name="compile" depends="init" description="compile the source files">
<mkdir dir="${classes.dir}"/>
<javac srcdir = "${src.dir}" destdir = "${classes.dir}" source = "1.6" target="1.6">
<classpath refid = "master-classpath"/>
</javac>
</target>
<!--test-->
<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>
<!--make .jars-->
<target name = "pack" depends="test" description="make .jar files">
<mkdir dir="${dist.dir}"/>
<jar destfile = "${dist.dir}/ITHelpSystem.jar" basedir = "${classes.dir}">
<exclude name = "**/*Test.*"/>
<exclude name = "**/Test*.*"/>
</jar>
</target>
<!--create api doc-->
<target name="doc" depends = "pack" description = "create api doc">
<mkdir dir = "${doc.dir}"/>
<javadoc destdir = "${doc.dir}"
author = "true"
version = "true"
use = "true"
windowtitle = "ITHelpSystem API">
<packageset dir = "${src.dir}" defaultexcludes = "yes">
<include name = "com/**"/>
</packageset>
<doctitle><![CDATA[<h1>Hello,ITHelpSystem</h1>]]></doctitle>
<bottom><![CDATA[<i>ALL Rigths Reserved.</i>]]></bottom>
<!--<tag name = "todo" scope = "all" description = "To do:"/>-->
</javadoc>
</target>
<!-- Clean -->
<target name="clean" depends="init">
<delete>
<fileset dir="${classes.dir}" includes="**/*.class"/>
</delete>
</target>
</project>
...全文
37 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
caitianxiwo 2011-12-14
使用ant编译、运行junit、以及检查编码

<?xml version="1.0" encoding="gb2312"?>
<project name="Test Project" default="all" basedir=".">
<property name="src.code" value="src" />
<property name="src.junit" value="junit" />
<property name="lib.dir" value="lib" />
<property name="lib.jar" value="TestClass.jar" />
<!-- checkstyle configuration -->
<property name="checkstyle.config" value="checkstyle.xml" />
<taskdef resource="checkstyletask.properties"
classpath="${lib.dir}/checkstyle-all-3.1.jar" />
<!-- 输出文档 -->
<property name="doc.dir" value="doc" />
<property name="doc.api" value="${doc.dir}/api" />
<property name="javadoc.package" value="com.*" />
<!-- 输出二进制文件 -->
<property name="dist.root" value="dist" />
<property name="dist.proj" value="${dist.root}/proj" />
<property name="dist.classes" value="${dist.proj}/classes" />
<property name="dist.lib" value="${dist.proj}/lib" />
<property name="dist.junit" value="${dist.root}/junit" />
<!-- classpath -->
<path id="classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="proj.libs">
<fileset dir="${dist.lib}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="init">
<mkdir dir="${doc.dir}" />
<mkdir dir="${dist.root}" />
<mkdir dir="${dist.proj}" />
<mkdir dir="${dist.lib}" />
<tstamp />
<echo message="${TSTAMP}"></echo>
</target>
<target name="all" depends="compilesrc, javadoc, checkstyle" />
<!-- 编译源文件 -->
<target name="compilesrc" depends="init">
<mkdir dir="${dist.classes}" />
<javac destdir="${dist.classes}" deprecation="on">
<src path="${src.code}" />
<classpath refid="classpath" />
</javac>
<jar jarfile="${dist.lib}/${lib.jar}"
basedir="${dist.classes}">
<include name="**/*.class" />
</jar>
</target>
<!-- 产生javadoc -->
<target name="javadoc" depends="init">
<mkdir dir="${doc.api}" />
<javadoc packagenames="${javadoc.package}"
sourcepath="${src.code}" private="yes" defaultexcludes="yes"
destdir="${doc.dir}/api">
<classpath refid="classpath" />
</javadoc>
</target>
<!-- 编译Junit文件 -->
<target name="compilejunit" depends="compilesrc">
<mkdir dir="${dist.junit}" />
<javac destdir="${dist.junit}" deprecation="on">
<src path="${src.junit}" />
<classpath refid="classpath" />
<classpath refid="proj.libs" />
</javac>
</target>
<!-- 运行checkstyle检查代码规范 -->
<target name="checkstyle" depends="init">
<checkstyle config="${checkstyle.config}">
<fileset dir="${src.code}" includes="**/*.java" />
<formatter type="plain" />
<formatter type="xml"
toFile="${dist.root}/checkstyle_errors.xml" />
</checkstyle>
</target>
<!-- 运行junit -->
<target name="junit" depends="compilejunit">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<path refid="classpath" />
<pathelement location="${dist.junit}" />
</classpath>
<formatter type="plain" />
<!-- test name="com.TestClassTest" haltonfailure="no" outfile="result"/ -->
<batchtest todir="${dist.junit}">
<fileset dir="${dist.junit}" includes="**/Test*.class" />
</batchtest>
</junit>
</target>
<!-- 清除产生的类、junit相关类、文档 -->
<target name="clean">
<delete dir="${dist.classes}" />
<delete dir="${dist.junit}" />
<delete dir="${doc.api}" />
</target>
<!-- 清除所有输出结果 -->
<target name="cleanall" depends="clean">
<delete dir="${doc.dir}" />
<delete dir="${dist.root}" />
</target>
</project>
回复
相关推荐
发帖
非技术区
创建于2007-09-28

2.3w+

社区成员

Java 非技术区
申请成为版主
帖子事件
创建了帖子
2011-12-14 09:14
社区公告
暂无公告