ANT 自动编译打包发布卸载脚本

    网上看了很多此类脚本,要不就是太简单,要不就是太复杂。要想找到适合自己的脚本,还不如自己动手写一个。此脚本仅供备份,参考。

<?xml version="1.0" encoding="utf-8" ?> 
<project name="userfilter" default="" basedir=".."> 
        <property environment="env" /> 
<property name="java.home" value="env.JAVA_HOME" />
        <property name="src.dir" value="${basedir}/src" /> 
<property name="app.home" value="应用程序lib包地址"/>
<property name="web.dir" value="WebRoot" />
<property name="tomcat.home" value="tomcat lib地址" />
<property name="dest.jar" value="${basedir}\WebRoot\WEB-INF\lib"/>
<property name="dist.dir" value="${basedir}\WebRoot\dist" />
        <property name="build.dir" value="${basedir}\WebRoot\build"/>

<path id="build.classpath">
<fileset dir="${tomcat.home}">
<include name="*.jar"/>
</fileset>
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${build.dir}"/>
</path>

<target name="clean" description="清空">
<delete dir="${build.dir}" />
    <delete dir="${dist.dir}" />
</target>

<target name="init" depends="clean" description="初始化">
<mkdir dir="${build.dir}" />
<mkdir dir="${dist.dir}" />
</target>

<target name="compile" depends="clean,init" description="编译">
<javac srcdir="${src.dir}" destdir="${build.dir}" fork="true"
executable="jdk地址 ../bin/javac" source="1.4" encoding="utf-8">
<classpath  refid="build.classpath"/>
</javac>
</target>

<target name="create-manifest" depends="compile">
<tstamp />
    <manifest file="${build.dir}/MANIFEST.MF">
<attribute name="Build-By" value="${user.name}" />
<attribute name="Build-On" value="${DSTAMP}${TSTAMP}" />
<attribute name="JDK-Version" value="1.4" />
</manifest>
</target>

<target name="jar" depends="create-manifest" description="创建发布包">
<jar destfile="${dist.dir}\${ant.project.name}.jar" manifest="${build.dir}/MANIFEST.MF">
<fileset dir="${build.dir}">
<include name="**/*.class"/>
</fileset>
</jar>
</target>

<target name="deploy" depends="jar" description="发布">
<copy file="${dist.dir}\${ant.project.name}.jar" todir="${app.home}">  </copy>
</target>


<target name="undeploy" description="删除jar">
<delete file="${app.home}\${ant.project.name}.jar" />
</target>
</project>

你可能感兴趣的:(xml,ant,脚本)