要实现ant可以从svn服务器上检出代码要使用svnant jar文件。
从网上下载svnant 包,下载地址:
http://subclipse.tigris.org/files/documents/906/49042/svnant-1.3.1.zip
将下载好的svnant 解压将 lib目录下的所有jar复制到ant主目录中的 lib目录下。
编写build.xml
要svn task任务可以使用要在build.xml中添加
- <typedefresource="org/tigris/subversion/svnant/svnantlib.xml"/>
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" />
完整的xml文件如下:
- <projectname="dt"basedir=".">
- <!--定义属性-->
- <propertyname="src"value="src/main/java"/>
- <propertyname="resources"value="src/main/resources"/>
- <propertyname="test"value="test"></property>
- <propertyname="target"value="target"></property>
- <propertyname="main-target"value="target/classes"/>
- <propertyname="test-target"value="target/test-classes"/>
- <propertyname="lib-dir"value="WebContent/WEB-INF/lib"/>
- <propertyname="tomcat.home"value="D:/webapp-server/apache-tomcat-6.0.20"/>
- <!--antlib目录>
- <propertyname="ant-lib-dir"value="D:/apache-ant-1.8.2/lib"/>
- <!--需指向本地tomcatlib目录-->
- <propertyname="tomcat-lib"value="D:/webapp-server/apache-tomcat-6.0.20/lib"/>
- <!--svn路径-->
- <propertyname="urlRepos"value="svn://192.168.1.1o/Project/dt"/>
- <!--定义classpath-->
- <pathid="classpath">
- <filesetdir="${lib-dir}"includes="***.jar"></fileset>
- <filesetdir="${tomcat-lib}"includes="***.jar"></fileset>
- </path>
- <!--引用svntask文件,使用svn任务可以使用-->
- <typedefresource="org/tigris/subversion/svnant/svnantlib.xml"/>
- <!--清理-->
- <targetname="clean">
- <deletedir="${target}"></delete>
- </target>
- <!--初始化-->
- <targetname="init"depends="clean">
- <mkdirdir="${main-target}"/>
- <mkdirdir="${test-target}"/>
- </target>
- <!--设置svn相关属性-->
- <svnSettingid="svn.setting"svnkit="true"username="hzl"password="111111"javahl="false"/>
- <!--检出代码这里使用export不是checkout二者区别checkout会svn相关信息文件检出,export只是检出最新的文件-->
- <targetname="checkout"depends="clean">
- <svnrefid="svn.setting">
- <exportsrcUrl="${urlRepos}"destPath="."force="true"/>
- </svn>
- </target>
- <!--编译-->
- <targetname="compile"depends="checkout">
- <javacsrcdir="${src}"destdir="${main-target}"encoding="UTF-8"includeAntRuntime="false">
- <classpathrefid="classpath"></classpath>
- </javac>
- <copytodir="${main-target}">
- <filesetdir="${resources}">
- <excludename="sql/**"/>
- </fileset>
- </copy>
- </target>
- <!--打war包-->
- <targetname="build"depends="compile">
- <wardestfile="${target}/dt.war"webxml="WebContent/WEB-INF/web.xml">
- <filesetdir="WebContent"></fileset>
- <classesdir="${main-target}"></classes>
- </war>
- <deletedir="${main-target}"></delete>
- <deletedir="${test-target}"></delete>
- </target>
- <!--shutdowntomcat-->
- <targetname="shutdowntomcat"description="========shutdowntomcat===========">
- <execexecutable="${tomcat.home}/bin/shutdown.sh"failonerror="false"></exec>
- <sleepseconds="10"/>
- </target>
- <!--startuptomcat-->
- <targetname="startuptomcat"description="========startuptomcat===========">
- <sleepseconds="5"/>
- <execexecutable="${tomcat.home}/bin/startup.sh"failonerror="false"></exec>
- </target>
- <!--部署到tomcat下面-->
- <targetname="deploy"depends="war">
- <copyfile="${target}/dt.war"todir="${tomcat.home}/webapps"/>
- </target>
- </project>