项目成员认为发布应用到weblogic比较麻烦,于是写一个ant脚本帮助自动发布到测试环境。全文如下:
build.properties的内容:
temp.folder=E://tools//cruisecontrol-bin-2.8.2//target
deploy.ear=E://deploy//cluster//uuim.ear
j2ee.lib=E://Tomcat//common//lib/
weblogic.lib=C://bea/weblogic92//server//lib
username=weblogic
password=weblogic
application.name=uuim
adminurl=t3://192.168.1.189:8001
target=ManagedServer2
这里定义了构建文件使用的基本变量。
构建文件build.xml的内容:
- <project name="uuim" default="packageForTest" basedir=".">
- <property file="build.properties" />
- <property name="appName" value="${application.name}" />
- <property name="classesPath" value="WebContent/WEB-INF/classes" />
- <!-- 初始化weblogic发布任务 -->
- <target name="init">
- <path id="project.class.path">
- <pathelement path="${java.class.path}/" />
- <pathelement path="${weblogic.lib}/weblogic.jar" />
- </path>
- <echo message="${java.class.path}" />
- <taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
- <classpath refid="project.class.path" />
- </taskdef>
- </target>
- <!-- 发布 -->
- <target name="deploye-to-weblogic" depends="packageForLocalTest,init">
- <wldeploy action="undeploy" verbose="true" debug="true" name="${appName}" user="${username}" password="${password}" adminurl="${adminurl}" targets="${target}" />
- <wldeploy action="activate" source="${deploy.ear}" verbose="true" debug="true" name="${appName}" user="${username}" password="${password}" adminurl="${adminurl}" targets="${target}" />
- </target>
- <!-- 打包 -->
- <target name="packageForLocalTest" depends="compile">
- <copy file="${classesPath}/config_189.properties" tofile="${classesPath}/config.properties" overwrite="true" />
- <copy todir="${temp.folder}/${appName}.ear/${appName}.war/">
- <fileset dir="WebContent">
- <exclude name="*.svn/**" />
- </fileset>
- </copy>
- <zip destfile="${deploy.ear}" basedir="${temp.folder}/${appName}.ear" excludes="*.svn/**" />
- </target>
- <!-- 从svn更新代码到本地 -->
- <target name="svnup">
- <exec executable="svn">
- <arg line="up" />
- </exec>
- </target>
- <!-- 清除以前构建的文件 -->
- <target name="clean">
- <delete includeEmptyDirs="true">
- <fileset dir="${classesPath}" includes="**/*"/>
- <fileset dir="${temp.folder}/${appName}.ear/${appName}.war/" includes="**/*"/>
- </delete>
- </target>
- <!-- 设置编译classpath -->
- <path id="lib">
- <fileset dir="WebContent/WEB-INF/lib/">
- <include name="**/*.jar" />
- </fileset>
- <fileset dir="${j2ee.lib}">
- <include name="**/*.jar" />
- </fileset>
- </path>
- <!-- 编译 -->
- <target name="compile" depends="svnup,resource">
- <javac srcdir="src" destdir="WebContent/WEB-INF/classes" encoding="UTF-8" classpathref="lib" />
- </target>
- <!-- 拷贝资源文件 -->
- <target name="resource" >
- <copy todir="WebContent/WEB-INF/classes">
- <fileset dir="src">
- <include name="**/*.jpe" />
- <include name="**/*.jpeg" />
- <include name="**/*.rmf" />
- <include name="**/*.wav" />
- <include name="**/*.mid" />
- <include name="**/*.midi" />
- <include name="**/*.au" />
- <include name="**/*.gif" />
- <include name="**/*.png" />
- <include name="**/*.jpg" />
- <include name="**/*.aiff" />
- <include name="**/*.properties" />
- <include name="**/*.xml" />
- <include name="**/*.swf" />
- </fileset>
- </copy>
- </target>
- </project>