当前位置: 代码迷 >> Web前端 >> ant使用
  详细解决方案

ant使用

热度:293   发布时间:2012-11-11 10:07:57.0
ant应用

提高自己学习的一个ant应用,作为一个记录
<?xml version="1.0" encoding="UTF-8"?>
<!-- ********************************************************-->
<!--                      author:gramind                     --> 
<!--                      date:  2011.01.12                  -->
<!-- ******************************************************* -->
  
<project name="pre-fit" default="appbuild" basedir=".">
    
	<!--File and Directory Names  文件和目录设置  
	    app.web             应用路径
		app.name             发布到tomcat的应用的名字  
		app.version          应用的版本标识  
		dist.home            war包位置,默认为"dist"  
		dist.build           编译目标位置,默认为"dist/build" 
	-->
	<property name="app.web" value="webapp" />
	<property name="app.name" value="myapp" />
	<property name="dist.home" value="dist" />
	<property name="dist.build" value="${dist.home}/build" />
	<!--Compilation Control Options 编译控制选项  
		compile.debug        是否包含debug信息  
		compile.deprecation    
		compile.optimize     是否优化编译  
	-->
	<property name="compile.debug" value="true" />
	<property name="compile.deprecation" value="false" />
	<property name="compile.optimize" value="true" />
	<property name="compile.encoding" value="gbk" />
	<tstamp prefix="buildtime"> 
	    <format property="dt" pattern="yyyy_MM_dd"/> 
	</tstamp> 

	<!-- Compilation Classpath 路径设置-->
	<path id="compile.classpath">
		<fileset dir="${app.web}/WEB-INF/lib">
			<include name="*.jar" />
		</fileset>
	</path>

	<!--Prepare Target 建立打包的目的目录结构-->
	<target name="prepare">
		<!-- Delete voertime disk dir -->
		<delete dir="${dist.home}" />
		<!-- Compile Java classes as necessary -->
		<mkdir dir="${dist.build}" />
		<mkdir dir="${dist.build}/classes" />
	</target>

	<!--Compile Target 编译代码,在这之前先由prepare建立目录结构-->
	<target name="compile" depends="prepare" description="Compile Java sources">
		<javac srcdir="src" destdir="${dist.build}/classes" encoding="${compile.encoding}" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
			<classpath refid="compile.classpath" />
		</javac>
		<copy todir="${dist.build}/library/classes">
			<fileset dir="src" excludes="**/*.java" />
		</copy>
	</target>
	
	<!--Jar Target 源码打jar包-->
	<target name="makejar" depends="compile">
		<jar compress="false" destfile="${dist.build}/${app.name}.jar">
			<fileset dir="${dist.build}/classes" includes="**" />
		</jar>
	</target>
				
	<!--Javadoc Target 生成javadoc-->
	<target name="javadoc" depends="compile" description="Create Javadoc API documentation">
		<mkdir dir="${dist.home}/docs/api" />
		<javadoc sourcepath="src" encoding="${compile.encoding}" destdir="${dist.home}/docs/api" packagenames="com.*" />
	</target>
	
	<!--Deploy Target 在tomcat下建立应用目录并部署应用-->
	<target name="makewar" depends="makejar">
		<delete dir="${app.web}/WEB-INF/classes" />
		<copydir dest="${app.web}/WEB-INF/classes" src="${dist.build}/library/classes"></copydir>
		<war warfile="${dist.home}/${app.name}.war" webxml="${app.web}/WEB-INF/web.xml">
			<lib dir="${app.web}/WEB-INF/lib" />
			<fileset dir="${app.web}" />
		</war>
	</target>
	
	<!--backup Target 备份源码-->
	<target name="backup" depends="makewar">
		<zip basedir="." destfile="${dist.home}/${app.name}_${buildtime.dt}.zip" includes="src/** webapp/**" />
	</target>
	
	<!--Clean Target 删除先前的目录结构-->
	<target name="clean" description="Delete old build and dist directories">
		<delete dir="${dist.build}" />
	</target>
	
	<target name="begin">
		<echo>+---------------------------+</echo>
		<echo>+             Building  Application  Begin                      +</echo>
		<echo>+---------------------------+</echo>
	</target>
		
	<!--end -->
	<target name="end">
		<echo>+----------------------------+</echo>
		<echo>+             Building  Application  End                         +</echo>
		<echo>+----------------------------+</echo>
	</target>
	
	<target name="appbuild" depends="begin,prepare,compile,javadoc,makejar,makewar,backup,clean,end" />
	
</project>
  相关解决方案