利用ant自动从vss下载代码并编译到自动发布
项目做了好久,每次都要手工从vss下载代码,再编译,再发布,觉得好麻烦的,以前项目比较忙就没有时间来研究他,昨天无意在网上看到一个基于wls自 动发布过来,个人认为可以改下为我们所用了,由于自己以前对ant这些东西不是蛮了解,只好先硬着头皮到网上找些这方面的资料看看,我想应该比较容易搞定 的吧。
<target name="all" depends="compile,deploy,backup" description="Build application"/>
<!--Backup-->
<target name="backup">
<tstamp/>
<mkdir dir="${hist.dir}/${TODAY}"/>
<mkdir dir="${hist.dir}/${TODAY}/coding"/>
<mkdir dir="${hist.dir}/${TODAY}/deploy"/>
<mkdir dir="${hist.dir}/${TODAY}/db"/>
搞清了ant的一些基本概率,就看看别人写的bulid.xml吧,再改改,试一试,唉,报错,再找到报错的日志,可能是配置文件中有汉字的缘故吧,删除这些注释的东西,再运行下ant,搞定!(基于tomcat发布的)
如下是bulid.xml的详细列表;
<project name="oa" basedir="." default="all">
<!--path mapping-->
<property file="build.properties"/>
<property name="name" value="OA"/>
<property name="base.dir" value="checkout/${name}/oa-web-app"/>
<property name="src.dir" value="${base.dir}/src"/>
<property name="bin.dir" value="${base.dir}/war/WEB-INF/classes"/>
<property name="lib.dir" value="${base.dir}/war/WEB-INF/lib"/>
<property name="dist.dir" value="D:/oaWorkspace/jakarta-tomcat-5.5.9/webapps/${name}"/>
<property name="hist.dir" value="history/${name}"/>
<property name="appserver.home" value="D:/oaWorkspace/jakarta-tomcat-5.5.9"/>
<property file="build.properties"/>
<property name="name" value="OA"/>
<property name="base.dir" value="checkout/${name}/oa-web-app"/>
<property name="src.dir" value="${base.dir}/src"/>
<property name="bin.dir" value="${base.dir}/war/WEB-INF/classes"/>
<property name="lib.dir" value="${base.dir}/war/WEB-INF/lib"/>
<property name="dist.dir" value="D:/oaWorkspace/jakarta-tomcat-5.5.9/webapps/${name}"/>
<property name="hist.dir" value="history/${name}"/>
<property name="appserver.home" value="D:/oaWorkspace/jakarta-tomcat-5.5.9"/>
<property name="vss.ssdir" value="D:/oaWorkspace/vss/win32"/>
<property name="vss.svrdir" value="H:"/>
<property name="vss.svrdir" value="H:"/>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath>
<path location="${appserver.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath>
<path location="${appserver.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath>
<path location="${appserver.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<path id="appClassPath">
<pathelement path="${java.class.path}"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<classpath>
<path location="${appserver.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath>
<path location="${appserver.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath>
<path location="${appserver.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<path id="appClassPath">
<pathelement path="${java.class.path}"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="getVssCode">
<tstamp>
<format property="TODAY" pattern="yyyy-MM-dd" />
</tstamp>
<echo message="Getting latest source codes from: ${TODAY}" />
<echo message="${vss.svrdir}" />
<vssget vsspath="/E.OA系统产品/5.开发库/1.代码库/1.源代码/OA/oa-web-app" localpath="${base.dir}" login="name,password"
ssdir="${vss.ssdir}" serverPath="${vss.svrdir}" autoresponse="Y" recursive="true" quiet="true" />
</target>
<tstamp>
<format property="TODAY" pattern="yyyy-MM-dd" />
</tstamp>
<echo message="Getting latest source codes from: ${TODAY}" />
<echo message="${vss.svrdir}" />
<vssget vsspath="/E.OA系统产品/5.开发库/1.代码库/1.源代码/OA/oa-web-app" localpath="${base.dir}" login="name,password"
ssdir="${vss.ssdir}" serverPath="${vss.svrdir}" autoresponse="Y" recursive="true" quiet="true" />
</target>
<target name="all" depends="compile,deploy,backup" description="Build application"/>
<!--Clean-->
<target name="clean">
<delete includeEmptyDirs="true">
<fileset dir="${base.dir}" />
</delete>
</target>
<target name="clean">
<delete includeEmptyDirs="true">
<fileset dir="${base.dir}" />
</delete>
</target>
<!--Init-->
<target name="init">
<mkdir dir="${base.dir}"/>
</target>
<target name="init">
<mkdir dir="${base.dir}"/>
</target>
<!--Compile-->
<target name="compile">
<javac srcdir="${src.dir}" destdir="${bin.dir}" fork="on" optimize="off" deprecation="on" memoryMaximumSize="128m">
<classpath refid="appClassPath"/>
</javac>
<native2ascii src="${src.dir}" dest="${bin.dir}"
includes="*_zh_CN.properties" excludes="*displaytag_zh_CN.properties" encoding="GB2312" />
<native2ascii src="${src.dir}" dest="${bin.dir}"
includes="*displaytag_zh_CN.properties" encoding="UTF-8" />
<copy todir="${bin.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.java"/>
<include name="**/*.xml"/>
</fileset>
</copy>
<target name="compile">
<javac srcdir="${src.dir}" destdir="${bin.dir}" fork="on" optimize="off" deprecation="on" memoryMaximumSize="128m">
<classpath refid="appClassPath"/>
</javac>
<native2ascii src="${src.dir}" dest="${bin.dir}"
includes="*_zh_CN.properties" excludes="*displaytag_zh_CN.properties" encoding="GB2312" />
<native2ascii src="${src.dir}" dest="${bin.dir}"
includes="*displaytag_zh_CN.properties" encoding="UTF-8" />
<copy todir="${bin.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.java"/>
<include name="**/*.xml"/>
</fileset>
</copy>
<copy todir="${bin.dir}">
<fileset dir="${src.dir}">
<exclude name="*_zh_CN.properties"/>
<include name="*.properties"/>
</fileset>
</copy>
</target>
<fileset dir="${src.dir}">
<exclude name="*_zh_CN.properties"/>
<include name="*.properties"/>
</fileset>
</copy>
</target>
<!--Deploy-->
<target name="deploy">
<delete includeEmptyDirs="true">
<fileset dir="${dist.dir}/WEB-INF/classes"/>
</delete>
<copy todir="${dist.dir}">
<fileset dir="${base.dir}/war"/>
</copy>
</target>
<target name="deploy">
<delete includeEmptyDirs="true">
<fileset dir="${dist.dir}/WEB-INF/classes"/>
</delete>
<copy todir="${dist.dir}">
<fileset dir="${base.dir}/war"/>
</copy>
</target>
<!--Backup-->
<target name="backup">
<tstamp/>
<mkdir dir="${hist.dir}/${TODAY}"/>
<mkdir dir="${hist.dir}/${TODAY}/coding"/>
<mkdir dir="${hist.dir}/${TODAY}/deploy"/>
<mkdir dir="${hist.dir}/${TODAY}/db"/>
<copy todir="${hist.dir}/${TODAY}/coding">
<fileset dir="${base.dir}"/>
</copy>
<copy todir="${hist.dir}/${TODAY}/deploy">
<fileset dir="${dist.dir}"/>
</copy>
</target>
<fileset dir="${base.dir}"/>
</copy>
<copy todir="${hist.dir}/${TODAY}/deploy">
<fileset dir="${dist.dir}"/>
</copy>
</target>
<target name="stop" description="Stop application in Tomcat">
<stop url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<stop url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="reload" description="Reload application in Tomcat">
<reload url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<reload url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="start" description="start application in Tomcat">
<start url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
</project>
<start url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
</project>
少了一个文件build.properties的内容
# Ant properties for building the spring
user.home=D:/oaWorkspace
appappserver.home=${user.home}/jakarta-tomcat-5.5.9
deploy.path=${appserver.home}/webapps
tomcat.manager.url=http://127.0.0.1/manager
tomcat.manager.username=manager
tomcat.manager.password=tomcat
user.home=D:/oaWorkspace
appappserver.home=${user.home}/jakarta-tomcat-5.5.9
deploy.path=${appserver.home}/webapps
tomcat.manager.url=http://127.0.0.1/manager
tomcat.manager.username=manager
tomcat.manager.password=tomcat