ant build.xml 文件

原文地址:http://blog.csdn.net/xiaxiaozhang/article/details/74155300

<?xml version="1.0" encoding="UTF-8"?>  
<project name="myweb" default="deploy" basedir=".">  
    <property environment="env" />  
    <property name="webapp.name" value="myweb" />  
    <property name="catalina.home" value="D:\tomcat\apache-tomcat-7.0.75 - myself" />  
    <property name="dist.dir" value="${basedir}/dist" />  
    <property name="ant.dir" value="D:\tomcat\apache-ant-1.10.1-bin\apache-ant-1.10.1" />  
    <property name="webRoot.dir" value="${basedir}/WebRoot" />  
    <property name="src.dir" value="${basedir}/src" />  
    <property name="config.dir" value="${basedir}/config" />  
    <property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" />  
    <property name="build.dir" value="${basedir}/build" />  
    <!-- 使用eclipse jdt进行编译,而不使用JDK编译  -->  
    <!-- <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />  -->  
    <!-- <property name="build.compiler" value="D:\MyWorkApps\Java\jdk1.8.0_51" /> -->  
  
    <!-- 初始化classpath -->  
    <path id="project.classpath">  
        <fileset dir="${lib.dir}">  
            <include name="**/*.jar" />  
        </fileset>  
        <!-- 添加tomcat类路径 -->  
        <fileset dir="${catalina.home}/lib">  
            <include name="*.jar" />  
        </fileset>  
        <!-- ant lib包  -->  
        <fileset dir="${ant.dir}">  
            <include name="**/*.jar" />  
        </fileset>  
    </path>  
  
    <!-- get the source compile classpath in a printable form -->  
    <pathconvert pathsep="${line.separator}|   |-- "  
             property="echo.path.compile"  
             refid="project.classpath">  
    </pathconvert>  
      
    <!-- show classpath jars -->  
    <target name="print_classpath">  
        <echo message="|-- compile classpath"/>  
        <echo message="|   |"/>  
        <echo message="|   |-- ${echo.path.compile}"/>  
    </target>  
      
      
    <!-- 删除之前的目录结构 -->  
    <target name="clear" description="清理旧文件">  
        <delete dir="${build.dir}" />  
        <delete dir="${dist.dir}" />  
        <delete file="${catalina.home}/webapps/${webapp.name}.war" />  
        <delete dir="${catalina.home}/webapps/${webapp.name}" />  
    </target>  
  
    <!-- 创建目录结构 -->  
    <target name="init" depends="clear" description="创建初始化目录结构">  
        <mkdir dir="${build.dir}/classes" />  
        <mkdir dir="${dist.dir}" />  
    </target>  
  
    <!-- 编译java -->  
    <target name="compile" depends="init" description="编译java文件">  
        <echo message="begin compile..." />  
        <javac srcdir="${src.dir}" destdir="${build.dir}/classes"   
            includeantruntime="false" nowarn="on"   
            source="1.7" target="1.7" deprecation="true" debug="true"   
            encoding="UTF-8" classpathref="project.classpath"   
            >  
            <compilerarg line="-Xlint:unchecked" />  
            <!-- <classpath refid="project.classpath" /> -->  
        </javac>  
        <copy todir="${build.dir}/classes">  
            <fileset dir="${src.dir}">  
                <include name="**/*.xml" />  
                <include name="**/*.properties" />  
                <include name="**/*.sql" />  
            </fileset>  
         <!--    <fileset dir="${config.dir}">  
                <include name="**/*.xml" />  
                <include name="**/*.properties" />  
                <include name="**/*.sql" />  
            </fileset>   -->
        </copy>  
        <echo message="end compile..." />  
    </target>  
  
    <!-- 将class文件打成 jar包 -->  
    <!--    
        <target name="pack" depends="compile">   
            <jar jarfile="${build.dir}/${webapp.name}.jar">   
                <fileset dir="${build.dir}/classes">   
                    <include name="**/*.class"/>   
                </fileset>   
            </jar>   
        </target>   
    -->  
  
    <!-- 打成war包, 名称默认为 项目名 -->  
    <target name="war" depends="compile" description="将工程打成war包">  
        <echo message="begin war..." />  
        <war destfile="${dist.dir}/${webapp.name}.war" basedir="${webRoot.dir}"   
            webxml="${webRoot.dir}/WEB-INF/web.xml">  
            <lib dir="${lib.dir}" />  
            <classes dir="${build.dir}/classes" />  
            <fileset dir="${webRoot.dir}">  
                <include name="***.*" />  
            </fileset>  
        </war>  
        <echo message="end war..." />  
    </target>  
  
    <!-- copy war包 tomcat的deploy目录 -->  
    <target name="deploy" depends="war" description="部署项目">  
        <echo message="begin deploy..." />  
        <copy file="${dist.dir}/${webapp.name}.war" todir="${catalina.home}/webapps" />  
        <echo message="end deploy..." />  
    </target>  
  
</project>  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值