Ant打包生成zip

代码总览

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project default="zip">
	<property name="src.dir" location="src" />
	<property name="build.dir" location="build" />
	<property name="build.doc" location="${build.dir}/doc/api" />
	<property name="packagenames" value="com.itlwc.*" />
	<property name="zip.dir" location="${build.dir}/zip" />
	
	<target name="clean">
		<delete dir="${build.dir}" />
	</target>

	<target name="createFolders" depends="clean">
		<mkdir dir="${build.dir}" />
		<mkdir dir="${build.doc}" />
		<mkdir dir="${zip.dir}" />
	</target>
	
	<target name="doc" depends="createFolders">
		<javadoc 
			sourcepath="${src.dir}" 
			packagenames="${packagenames}" 
			destdir="${build.doc}"
			charset="GBK"
			docencoding="GBK"
			encoding="GBK"
			private="true"
			windowtitle="MyStudentDoc"
			use="true">
		</javadoc>
	</target>
	
	<!--版本-->
	<property name="version" value="MyStudent_0.1"/>
	<!--包的名称-->
	<property name="zip.nane" value="Student_${version}.zip"/>
	<!--项目名-->
	<property name="project.name" value="Student_${version}"/>
	<!--打包-->
	<target name="zip" depends="doc">
		<!--
			destfile	目标文件
			duplicate	打包方式(一般使用preserve)
			zipfileset	打包那些文件
			prefix		增加前缀(使用最佳实践)
		-->
		<zip destfile="${zip.dir}/${zip.nane}" duplicate="preserve">
			<zipfileset dir="${build.doc}" includes="**/*.*" 
				prefix="${project.name}/doc/api"/>
			<zipfileset dir="${src.dir}" includes="**/*.*" 
				prefix="${project.name}/src"/>
		</zip>
	</target>
</project>

你可能感兴趣的:(Ant打包生成zip)