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>
<!-- 建立目录结构
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>
相关文章推荐
- Ant build.xml 构建文件 打包发布
- 通过ANT提高EJB应用的开发效率--build.xml
- 通用ANT编译发布打包启动tomcat的模板
- Android项目使用Ant打包,自动生成build.xml
- 【转】Android项目使用Ant打包,生成build.xml
- 建立web应用的 ant build.xml 模板
- 使用Ant发布web应用到tomcat
- java ant进行编译打包,build.xml文件编写
- ANT 发布项目中 build.xml 文件的详细配置
- ant创建 发布 EJB build.xml 文件的编写
- ANT 发布项目中 build.xml 文件的详细配置
- Ant 打包war 生成文件内容build.xml
- Android项目使用Ant打包,自动生成build.xml
- Ant打包报错 build.xml:601: The following error occurred while executing this line
- 在tomcat中配置上一个xml文件,直接访问建立的工程,无需重复发布
- Ant 对struts2+Ibatis+Spring3的项目编译,打包,发布到Tomcat
- Android用ant打包时更新build.xml(Mac)
- 使用ant脚本,对java web项目,编译、打包、发布部署到tomcat
- ant build.xml 打包应三方jar注意的问题与混淆R的写法
- ant-build.xml打包应用程序