您的位置:首页 > 运维架构 > Tomcat

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

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

<!-- 建立目录结构

project

... src J***A源码编辑目录

... 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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: