Ant 打包build.xml,并直接发布到tomcat应用

以下Ant打包工具,本人亲自实验了,发布的是WebService项目,红色部分根据开发工具而定,本人用的是eclipse,其中tomcat环境要看需要。。。

<!-- 建立目录结构 
        project 
            ... src                    JAVA源码编辑目录 
            ... WebContext     web文件存放地方 
                ... WEB-INF  
                    ...lib              jar包(类库)存放目录 
            ... build                编译生成的class文件存放目录 
            ... dist                  war和javadoc存放目录 
            ... build.xml         ant脚本 
 -->

<?xml version="1.0" encoding="UTF-8"?>

<project name="WebServiceTest" basedir=".">  
 
    <property name="src.dir" value="src"/>
    <property name="webContent.dir" value="WebContent"/>
    <property name="web-inf.dir" value="${webContent.dir}/WEB-INF"/>
    <property name="lib.dir" value="/WEB-INF/lib"/>
         
    <property name="build.dir" value="build"/>
    <property name="dist.dir" value="dist" />
    
     <!-- 指向环境变量的系统变量 -->
      <property environment="env"/>
      <!-- tomcat 路径 -->
      <property name="tomcat.home" value="${env.CATALINA_HOME}" />
       
        <!-- 初始化 classpath -->
        <path id="project.classpath">
            <fileset dir="${webContent.dir}/${lib.dir}">
                <include name="**/*.jar"/>
            </fileset>
         <!--添加tomcat类路径-->
          <fileset dir="${tomcat.home}/lib">
           <include name="*.jar"/>
           </fileset>

            <pathelement location="${build.dir}/classes"/>
            <pathelement path="${java.class.path}"/>
        </path>
         
        <!-- 删除之前的目录结构 -->
        <target name="clear">
            <delete dir="${build.dir}"/>
            <delete dir="${dist.dir}"/>
         <delete file="${tomcat.home}\webapps\${ant.project.name}.war"/>
         <delete dir="${tomcat.home}\webapps\${ant.project.name}"/>
        </target>
         
        <!-- 创建目录结构 -->
        <target name="init">
            <mkdir dir="${build.dir}/classes"/>
            <mkdir dir="${dist.dir}"/>
        </target>
         
        <!-- 编译Java代码 -->
        <target name="compile" depends="init" description="编译java文件">
            <javac srcdir="${src.dir}" destdir="${build.dir}/classes" includeantruntime="false">
                <compilerarg line="-encoding GBK"/>
                <classpath refid="project.classpath"/>  
            </javac>
            <copy todir="${build.dir}">
                <fileset dir="${src.dir}">
                    <include name="**/*.xml"/>
                    <include name="**/*.jar"/>
                </fileset>
            </copy>
        </target>
         
        <!-- 将class文件打成 jar包 -->
        <target name="pack" depends="compile">
            <jar jarfile="${build.dir}/${ant.project.name}.jar">
                <fileset dir="${build.dir}/classes">
                    <include name="**/*.class"/>
                </fileset>
            </jar>
        </target>
    
        <!-- 打成war包, 名称默认为 项目名 -->
        <target name="dist" depends="compile" description="将工程打成war包">
            <war destfile="${dist.dir}/${ant.project.name}.war" basedir="${webContent.dir}" webxml="${web-inf.dir}/web.xml"/>
        </target>
    
     <!-- copy war包 tomcat的deploy目录 -->
      <target name="deploy" depends="dist" description="部署工程">
       <copy file="${dist.dir}/${ant.project.name}.war"
        todir="${tomcat.home}\webapps" />
      </target>
 
</project> 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值