Use ant to automatically update svn, compile, submit svn

I recently switched to the database and started to do database-related work. I need to generate database->entities every day

And to import svn. Such repetitive work is often unbearable.

For convenience, I studied ant and found that I can use this tool to automatically upload svn, which is very convenient

Enough talk, let's get to work

1. Download the svnant package from the Internet (mine is svn1.6, currently svnant only supports 1.6 at the highest, and 1.7 can be replaced by something else, I have not studied it yet), download address:

http://subclipse.tigris.org/files/documents/906/49042/svnant-1.3.1.zip

Unzip the downloaded svnant and copy all the jars in the lib directory to the lib directory in the ant home directory.

2. Write build.xml

To svn task task can use to add in build.xml

 

<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" />  

 code show as below:

 

In order to reduce modification, we'd better use properties

I named it build.properties here, in fact, you can name it at will

Put something here, less modifying build.xml

 

##Put your project name here, the so-called generated jar name
prop.project.name=ctasdto
##ant location
ant.path=D:/apache-ant-1.8.2/lib
##Server location
server.path=D:/webapp-server/apache-tomcat-6.0.20
## Where you put the jar
dto.path=D:/work/XXX/output
## your svn path
svn.url=https://XXXX/svn/
## SVN username
svn.user=xiaoxiao
## SVN password
svn.passwd=password

 The following is the content of build.xml

 [Because files still need to be generated, so use eclipse's own compilation, here only package and upload]

 

<?xml version="1.0" encoding="gbk"?>

<project name="ctasdto" default="svn"  basedir=".">
    <!-- Load the content in the Property file, most of the content that needs to be modified is placed in the Property file-->
	<property resource="build.properties" />
	<property name="project.name" value="${prop.project.name}"/>
	<property name="src.dir" value="src" />
	<property name="classes.dir" value="classes"/>
	<property name="javadoc.dir" value="docs"/>
	<property name="obj.dir" value="${prop.dto.path}"/>
	<property name="jar.name" value="${prop.project.name}.jar"/>
	<property name="lib.dir" value="lib"/>
	<property name="svn.url"           value="${prop.svn.url}"/>
	<property name="svn.user"          value="${prop.svn.user}"/>
	<property name="svn.passwd"        value="${prop.svn.passwd}"/>
	<tstamp>
		<format property="buildtime"  pattern="yyyy-MM-dd-HH:mm:ss"/>
	</tstamp>
        <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" />
        <!-- Set svn related properties-->  
        <svnSetting id="svn.setting" svnkit="true" username="${svn.user}" password="${svn.passwd}"  javahl="false" />  
	<target name="svn.update" description="Update the local project for subsequent compilation">
		<echo>Update all information in ${obj.dir}</echo>
		<svn refid="svn.setting">  
            <checkout url="${svn.url}" destPath="${obj.dir}" force="true"/>  
        </svn>  
	</target>
	<target name="clear" depends="svn.update" description="Delete DTO file, it will be regenerated later">
	 <delete file="${obj.dir}\${jar.name}"/>
	</target>
	<target name="copyfile" depends="clear" description="copy source file to classes">
		<copy todir="${classes.dir}">
		   <fileset dir="${src.dir}">
  <!--Exclude list-->
		   	<exclude name="**/**"/>
		   	</fileset>	
		</copy>
		</target>
	<target name="build" depends="copyfile" description="包装成jar文件" >
		<jar jarfile="${obj.dir}/${jar.name}" basedir="${classes.dir}" >
             <!--Write the file location to be added here-->
			<include name="**/**"/>
			<include name="config/databaseconfig/**"/>
			<manifest>
				<attribute name="Project-Name" value="${project.name}"/>
				<attribute name="Project-Version" value="1.0"/>
				<attribute name="Project-BuildTime" value="${buildtime}"/>
			</manifest>
		</jar>
	</target>
	<target name="svn" depends="svn.update,clear,copyfile,build" description="上传svn">
		<svn refid="svn.setting">
			<commit file="output/${jar.name}" message="Automatically commit the latest dto.jar ${buildtime}"/>
		</svn>
	</target>
		
</project>

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326893913&siteId=291194637
svn