当前位置: 代码迷 >> XML/SOAP >> ant build.xml示范
  详细解决方案

ant build.xml示范

热度:859   发布时间:2013-12-21 20:16:01.0
ant build.xml示例
<?xml version="1.0" encoding="utf-8" ?>
<project default="all" basedir=".">
	<property environment="env" />
	<property name="appname" value="virt" />
	<property name="jarname" value="yoyo-virt" />
	<property name="mainclass" value="com.yoyosys.virt.navigation.service.SystemResourceMonitor" />
	<property name="src" value="src" />
	<property name="conf" value="conf" />
	<property name="build" value="${basedir}/build" />
	<property name="build.src" value="${build}/src" />
	<property name="build.class" value="${build}/class" />
	<property name="build.doc" value="${build}/doc" />

	<property name="debug" value="off" />
	<property name="optimize" value="on" />
	<property name="deprecation" value="on" />
	<property name="packages" value="com.yoyosys.virt.*" />

	<path id="classpath">
		<fileset dir="./WebContent/WEB-INF/lib">
			<include name="*.jar" />
		</fileset>
		<fileset dir="./lib">
			<include name="*.jar" />
		</fileset>
	</path>

	<target name="all" depends="init,build,jar" description="make all task." />

	<target name="init" depends="clean">
		<mkdir dir="${build}" />
		<mkdir dir="${build.src}" />
		<mkdir dir="${build.class}" />
		<mkdir dir="${build.doc}" />
		<copy todir="${build.src}">
			<fileset dir="${src}" />
			<fileset dir="${conf}" />
		</copy>
	</target>

	<target name="build" depends="init">
		<javac srcdir="${build.src}" destdir="${build.class}" encoding="UTF-8" debug="${debug}" optimize="${optimize}" deprecation="${deprecation}" includeantruntime="on">
			<include name="com/**/*.java" />
			<classpath refid="classpath" />
		</javac>
		<copy todir="${build.class}">
			<fileset dir="${build.src}">
				<include name="handlers/*" />
				<include name="rdb/*" />
			</fileset>
		</copy>
	</target>

	<target name="javadoc" depends="init">
		<javadoc packagenames="${packages}" sourcepath="${build.src}" destdir="${build.doc}" author="true" version="true" use="true" splitindex="true" windowtitle="${appname} API" doctitle="${appname}" charset="UTF-8" encoding="UTF-8" docencoding="UTF-8">
			<classpath refid="classpath" />
		</javadoc>
	</target>

	<target name="jar" depends="build">
		<pathconvert property="libs.project" pathsep=" ">
			<mapper>
				<chainedmapper>
					<!-- remove absolute path -->
					<flattenmapper />
					<!-- add lib/ prefix -->
					<globmapper from="*" to="lib/*" />
				</chainedmapper>
			</mapper>
			<path refid="classpath" />
		</pathconvert>

		<jar jarfile="${build}/${jarname}.jar" basedir="${build.class}" includes="**">
			<manifest>
				<attribute name="Main-Class" value="${mainclass}" />
				<attribute name="Class-Path" value="${libs.project}" />
			</manifest>
		</jar>
		<jar jarfile="${build}/${jarname}-doc.jar" basedir="${build.doc}" includes="**" />
		<jar jarfile="${build}/${jarname}-src.jar" basedir="${build.src}" includes="**" />
	</target>

	<target name="clean" description="clean up">
		<delete dir="${build}" />
	</target>

	<!-- checkstyle -->
	<property name="checkstyle-5.3.home" value="${env.YOYO_SVN_HOME}/app/java/checkstyle/checkstyle-5.3" />

	<fileset id="checkstyle-5.3.jar" dir="${checkstyle-5.3.home}">
		<include name="checkstyle-5.3-all.jar" />
	</fileset>

	<property name="checkstyle-latest.home" value="${checkstyle-5.3.home}" />
	<fileset id="checkstyle-latest.jar" refid="checkstyle-5.3.jar" />
	<taskdef resource="checkstyletask.properties" classpath="${checkstyle-5.3.home}/checkstyle-5.3-all.jar" />

	<target name="checkstyle" depends="build">
		<checkstyle config="${env.YOYO_SVN_HOME}/app/java/checkstyle/checkstyle.xml" failOnViolation="false">
			<fileset dir="${build.src}/com/yoyosys/virt">
				<include name="**/*.java" />
			</fileset>
			<formatter type="plain" />
			<formatter type="xml" toFile="${build}/checkstyle_report.xml" />
		</checkstyle>
		<xslt in="${build}/checkstyle_report.xml" out="${build}/checkstyle_report.html" style="${basedir}/checkstyle-noframes-severity-sorted.xsl" />
		<delete file="${build}/checkstyle_report.xml" />
	</target>

	<!-- findbugs -->
	<property name="findbugs.home" value="${env.YOYO_SVN_HOME}/app/java/findbugs/findbugs-2.0.0" />
	<path id="findbugs-jar">
		<pathelement path="${findbugs.home}/lib/findbugs-ant.jar" />
	</path>
	<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="findbugs-jar" />

	<target name="findbugs" depends="build">
		<findbugs home="${findbugs.home}" jvmargs="-server -Xss512m -Xmx1024m" output="xml:withMessages" outputFile="${build}/findbugs_report.xml" excludefilter="${basedir}/findbugs_exclude.xml" auxClasspathRef="classpath">
			<sourcePath path="${build.src}" />
			<class location="${build.class}" />
		</findbugs>
		<xslt in="${build}/findbugs_report.xml" out="${build}/findbugs_report.html" style="${basedir}/findbugs-fancy-hist.xsl" />
		<delete file="${build}/findbugs_report.xml" />
	</target>
</project>

  相关解决方案