CCS开发项目,通过Ant,将Common,EJB,Web三个模块,进行编译、打包、部署
build.xml
<?xml version="1.0" encoding="GBK"?> <!-- ======================================================================= --> <!-- JBoss build file --> <!-- ======================================================================= --> <!-- 银行信用系统构建脚本,部署CCS系统 --> <project name="CCS srcipt" default="deploy CCS" basedir="."><!-- 基目录为build.xml的当前目录 --> <!-- 定义环境 --> <property environment="env"/> <property name="src.dir" value="${basedir}/src"/> <!-- 源文件目录 --> <property name="build.dir" value="${basedir}/bin"/> <!-- 这里作为编译后临时的存放的目录 --> <property name="webapp.dir" value="${basedir}/src/webapp"/> <property name="jboss.home" value="${env.JBOSS_HOME}"/> <!-- JBoss目录 --> <property name="jboss.server.config" value="default"/> <!-- 文件夹名 --> <!-- 在构建时,编译源文件所依赖的类包的类路径 --> <!-- Build classpath --> <path id="classpath"> <fileset dir="${jboss.home}/lib"> <include name="**/*.jar"/> </fileset> <fileset dir="${jboss.home}/server/${jboss.server.config}/lib"> <include name="**/*.jar"/> </fileset> <fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/ejb3.deployer"> <include name="*.jar"/> </fileset> <fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/jboss-aop-jdk50.deployer"> <include name="*.jar"/> </fileset> <pathelement location="${build.dir}"/> <!-- 路径 --> </path> <!-- ================================================================ --> <!-- Common模块 --> <!-- ================================================================ --> <!-- 编译Common源代码 --> <target name="compile Common"> <!-- 目标 --> <delete dir="${build.dir}"/> <!-- 删除目录 --> <mkdir dir="${build.dir}"/> <!-- 创建目录 --> <!-- 编译 --> <javac destdir="${build.dir}" debug="on" deprecation="on" optimize="off" includes="**"> <src path="${src.dir}/common"/> <!-- 源文件目录 --> <classpath refid="classpath"/> <!-- 编译源文件所以的类 --> </javac> </target> <!-- 将Common模块打包 --> <target name="pack Common" depends="compile Common"> <!-- 触发执行上一个目标 --> <delete file="common.jar" /> <!-- 删除文件 --> <jar jarfile="common.jar"> <!-- 打包文件,默认放在基目录下 --> <fileset dir="${build.dir}"> <!-- 文件所在目录 --> <include name="**/*.class"/> <!-- 文件类型 --> </fileset> </jar> </target> <!-- ================================================================ --> <!-- EJB模块 --> <!-- ================================================================ --> <!-- 编译EJB源代码 --> <target name="compile EJB" depends="pack Common"> <delete dir="${build.dir}"/> <mkdir dir="${build.dir}"/> <javac destdir="${build.dir}" debug="on" deprecation="on" optimize="off" includes="**"> <src path="${src.dir}/model"/> <src path="${src.dir}/manager"/> <classpath refid="classpath"/> <!-- 编译源文件时所需要的类 --> <classpath> <fileset file="common.jar"/> <!-- 编译源文件时所引用的common包里的类 --> </classpath> </javac> </target> <!-- 将EJB模块打包 --> <target name="pack EJB" depends="compile EJB"> <delete file="ccs.jar" /> <jar jarfile="ccs.jar" manifest="manifest-ejb.mf"> <!-- 生成的MANIFEST.MF文件,引用自指定的文件 --> <fileset dir="${build.dir}"> <include name="**/*.class"/> </fileset> <fileset dir="${src.dir}/resources"/> </jar> </target> <!-- ================================================================ --> <!-- Web模块 --> <!-- ================================================================ --> <!-- 编译Web源代码 --> <target name="compile Web" depends="pack Common,pack EJB"> <delete dir="${webapp.dir}/WEB-INF/classes"/> <mkdir dir="${webapp.dir}/WEB-INF/classes"/> <javac destdir="${webapp.dir}/WEB-INF/classes" debug="on" deprecation="on" optimize="off" includes="**"> <src path="${src.dir}/view"/> <!-- 源文件目录 --> <classpath refid="classpath"/> <classpath> <fileset file="common.jar"/> </classpath> <classpath> <fileset file="ccs.jar"/> </classpath> <classpath> <fileset dir="${webapp.dir}/WEB-INF/lib"> <include name="*.jar"/> </fileset> </classpath> </javac> <copy todir="${webapp.dir}/WEB-INF/classes"> <!-- 复制配置文件 --> <fileset dir="${src.dir}/view" includes="*.xml,*.properties"/> </copy> </target> <!-- 将Web模块打包 --> <target name="pack Web" depends="compile Web"> <delete file="ccs.war" /> <!-- 生成war文件,引用现成的web.xml(以配置Web属性) --> <war destfile="ccs.war" update="true" webxml="${webapp.dir}/WEB-INF/web.xml" basedir="${webapp.dir}" manifest="manifest-web.mf" /> </target> <!-- ================================================================ --> <!-- 综合打包 --> <!-- ================================================================ --> <!-- 将COMMON、EJB、WEB打包为EAR --> <target name="pack COMMON EJB WEB into EAR" depends="pack Common,pack EJB,pack Web"> <delete file="ccs.ear" /> <!-- 生成ear文件,引用现成的application.xml(以配置EJB和Web的引用) --> <ear destfile="ccs.ear" update="true" appxml="${basedir}/application.xml" > <fileset dir="${basedir}" includes="common.jar,ccs.jar,ccs.war"/> </ear> </target> <!-- ================================================================ --> <!-- 最终部署 --> <!-- ================================================================ --> <!-- 部署CCS系统到JBoss --> <target name="deploy CCS" depends="pack COMMON EJB WEB into EAR"> <copy file="ccs.ear" overwrite="true" todir="${jboss.home}/server/${jboss.server.config}/deploy"/><!-- 文件覆盖 --> </target> </project>