您的位置:首页 > 编程语言 > Java开发

使用ant实现svn管理得eclipse插件开发项目的日构建功能(ant1.7.1+svn1.6.3+eclipse3.4.2)

2009-10-10 18:48 1226 查看
说明:本文由网上的文章结合自已的实战而成!

现在的项目发布版本是开发人员每隔一个周期更新代码并打包发布的,这样子做费时费力不说,还造成版本发布周期过长的问题。这样会让开发人员的工作得不到迅速的反馈。所以现在项目组有了日构建的构想,目的就是想减轻一些重复劳动,减短一些开发反馈周期。具体的工作是使用ant实现的,使用ant现在做到了 SVN下载代码,编译,打包,部署,邮件通知等功能。具体的实现方法如下:
[0]ant是基于java的,要使用ant首先必须安装一个JDK,可以去sun的网站下载,此不赘述。
[1]下载配置ant。可以到ant的官方网站去下载一个压缩包,地址:http://ant.apache.org/,解压到一个目录备用,我的路径为 /opt/apache-ant-1.7.1,下载后以后需要配置ant的环境变量ANT_HOME,Linux的话可以编辑/etc /environment文件中添加一行:
ANT_HOME="/opt/apache-ant-1.7.1"
在Windows中可以通过设置系统环境变量的方式添加,此不赘述。配置好环境变量后,需要将ant的可执行文件加到系统路径里面去,这样才能在命令行使用ant。Linux同样是编辑/etc/environment,在变量PATH中增加"/opt/apache-ant-1.7.1 /bin",Windows在环境变量编辑窗口的PATH条目中也增加类似"c:/apache-ant-1.7.1/bin"达到同样的效果。在 Linux的终端或者Windows的CMD窗口中输入:ant -version ,如看到类似下述信息,则说明ant已经配置好了:
Apache Ant version 1.7.1 compiled on June 27 2008。
[2]配置ant的SVN功能。要使ant能够运行svn任务,需要到如下地址下载一个svnant: http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=1731&expandFolder=1731&folderID=0 ,选择下载一个svnant.XXX.zip文件,然后解压后把其lib文件拷贝至ANT_HOME下面的lib去。
[3]如果本机没有SVN的客户端,还需要装一个SVN的命令行客户端工具,在终端下输入svn help,如果能看到以下字样,说明客户端工具已经配置好了:
usage: svn <subcommand> [options] [args]
Subversion command-line client, version 1.4.6.
Type 'svn help <subcommand>' for help on a specific subcommand.
Type 'svn --version' to see the program version and RA modules
or 'svn --version --quiet' to see just the version number.

Most subcommands take file and/or directory arguments, recursing
on the directories. If no arguments are supplied to such a
command, it recurses on the current directory (inclusive) by default.
[4]新建一个用于构建的目录,在里面编写一个ant脚本,默认名称为build.xml,具体内容如下:

========================================

<?xml version="1.0"?>
<project name="myproject" default="submit">
<!-- 定义目录变量 -->
<property name="svn.url" value="svn://localhost/myproject"/>
<property name="local.dir" value="./myproject"/>
<property name="src.dir" value="${local.dir}/src" />
<property name="bin.dir" value="${local.dir}/bin" />
<property name="base.dir" value="${local.dir}/." />
<property name="toolssrc.dir" value="${local.dir}/toolssrc" />
<property name="eclipse_plugins.dir" value="D:/eclipse-rcp-ganymede-SR2-win32/eclipse/plugins" />
<property name="dist.dir" value="AutoBuild/target" />
<property name="doc.dir" value="${dist.dir}/api" />
<property name="msg.commit" value="每日构建自动提交" />

<!-- 定义编译文件的支持库 -->
<path id="master-classpath">
<fileset dir="${eclipse_plugins.dir}" id="project_lib1">
<include name="org.eclipse.ui_3.4.2.M20090204-0800.jar"/>
<include name="org.eclipse.swt_3.4.2.v3452b.jar"/>
<include name="org.eclipse.swt.win32.win32.x86_3.4.1.v3452b.jar"/>
<include name="org.eclipse.jface_3.4.2.M20090107-0800.jar"/>
<include name="org.eclipse.core.commands_3.4.0.I20080509-2000.jar"/>
<include name="org.eclipse.ui.console_3.3.1.v20090128_r342.jar"/>
<include name="org.eclipse.ui.workbench_3.4.2.M20090127-1700.jar"/>
<include name="org.eclipse.core.runtime_3.4.0.v20080512.jar"/>
<include name="org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar"/>
<include name="org.eclipse.equinox.common_3.4.0.v20080421-2006.jar"/>
<include name="org.eclipse.core.jobs_3.4.1.R34x_v20081128.jar"/>
<include name="org.eclipse.core.runtime.compatibility.registry_3.2.200.v20080610/runtime_registry_compatibility.jar"/>
<include name="org.eclipse.equinox.registry_3.4.0.v20080516-0950.jar"/>
<include name="org.eclipse.equinox.preferences_3.2.201.R34x_v20080709.jar"/>
<include name="org.eclipse.core.contenttype_3.3.0.v20080604-1400.jar"/>
<include name="org.eclipse.ui.forms_3.3.103.v20081027_34x.jar"/>
<include name="com.ibm.icu_3.8.1.v20080530.jar"/>
<include name="org.eclipse.jface.databinding_1.2.1.M20080827-0800a.jar"/>
<include name="org.eclipse.equinox.app_1.1.0.v20080421-2006.jar"/>
<include name="org.eclipse.cdt.ui_4.0.0.200706261300.jar"/>
<include name="org.eclipse.ui.workbench.texteditor_3.4.1.r341_v20080827-1100.jar"/>
<include name="org.eclipse.core.resources_3.4.2.R34x_v20090126.jar"/>
<include name="org.eclipse.ui.ide_3.4.2.M20090127-1700.jar"/>
</fileset>
<fileset dir="${local.dir}/lib" id="project_lib2">
<include name="dom4j-1.6.1.jar"/>
<include name="jakarta-oro.jar"/>
<include name="jaxen-1.1.1.jar"/>
<include name="log4j-1.2.15.jar"/>
</fileset>
</path>
<path id="project.classpath">
<fileset dir="C:/apache-ant-1.7.1/lib" id="project_lib3">
<include name="svnjavahl.jar" />
<include name="svnant.jar" />
<include name="svnClientAdapter.jar" /></fileset>
</path>

<taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="project.classpath"/>

<!-- 首任务(空)-->
<target name="init"/>

<!--更新最新代码-->
<target name="update" depends="init">
<svn username="test" password="test">
<update dir="${local.dir}"/>
</svn>
</target>
<!-- 编译 -->
<target name="compile" depends="update">
<delete dir="${bin.dir}"/>
<mkdir dir="${bin.dir}"/>
<!--编译源程序-->
<javac srcdir="${src.dir}" destdir="${bin.dir}" target="1.5">
<classpath refid="master-classpath"/>
</javac>
<!--复制图标目录-->
<mkdir dir="${bin.dir}/icons"/>
<copy todir="${bin.dir}/icons">
<fileset dir="${local.dir}/icons"/>
</copy>
<!-- 复制srcml工具 -->
<mkdir dir="${bin.dir}/toolssrc"/>
<copy todir="${bin.dir}/toolssrc">
<fileset dir="${local.dir}/toolssrc">
</fileset>
</copy>
<!--复制日志等配置文件-->
<copy todir="${bin.dir}" flatten="true">
<fileset dir="${base.dir}">
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>
<copy todir="${bin.dir}" >
<fileset dir="${src.dir}" >
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>
<!-- 复制用到的jar包 -->
<mkdir dir="${bin.dir}/lib" />
<copy todir="${bin.dir}/lib">
<fileset refid="project_lib2"/>
</copy>
</target>

<!-- 打包 -->
<target name="pack" depends="compile">
<!-- bin目录压缩成JAR包 -->
<mkdir dir="${dist.dir}"/>
<!-- 删除指定目录下除svn版本文件外的其它项目文件 -->
<delete >
<fileset dir="${dist.dir}" excludes="**/*.*svn*"/>
</delete>
<jar basedir="${bin.dir}" destfile="${dist.dir}/com.cvicse.mspl.src_analyzing_1.0.0.jar" manifest="${local.dir}/META-INF/MANIFEST.MF"> <exclude name="**/*Test.*" />
<exclude name="**/Test*.*" />
</jar>
</target>

<!-- 输出api文档 -->

<target name="api_doc" depends="pack">
<mkdir dir="${doc.dir}"/>
<delete >
<fileset dir="${doc.dir}" excludes="**/*.*svn*"/>
</delete>
<javadoc destdir="${doc.dir}" author="true" version="true" use="true" windowtitle="myproject API">
<packageset dir="${src.dir}" defaultexcludes="yes"/>
<doctitle><!--[CDATA[<h1>src_analyzing Project</h1>]]></doctitle>
<bottom><![CDATA[<i>Document by fm2005 2009.</i>]]--></bottom>
</javadoc>
</target>

<!-- 提交到svn上 -->
<target name="add" depends="api_doc">
<svn username="test" password="test">
<add dir="${dist.dir}" force="true" />
</svn>
</target>
<target name="submit" depends="add">
<svn username="test" password="test">
<commit dir="${dist.dir}" message="${msg.commit}" />
</svn>
</target>
</project>

========================================

四. 执行方式:

如果你的项目在E:/test下,源码检出路径为:myproject目录,则可新建一AutoBuild目录,并手工提交到svn中。然后,把包含上面代码的build.xml文件放到E:/test下,然后运行就可以了。

windows系统可采用计划任务的方式来定时执行任务,Linux/UNIX系统则采用cron方式定时执行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐