下面的示例是一个用Ant执行数据库查询并通过Javamail发送邮件的例子,要完成相同的功能,请先安装下列步骤执行操作:
1、安装j2sdk1.4.2,并设置path和classpath
2、安装Ant161,加到path中去。
3、下载javamail-1.3.1,并在classpath中指定mail.jar
4、下载jaf-1.0.2,并在classpath中指定activation.jar
5、编辑buildfile文件,例如night_build.xml。
6、执行:ant -buildfile night_build.xml
7、添加计划任务(Linux下采用cron),定时执行以上脚本就可以实现nightly building。
night_build.xml脚本如下:
<?xml version="1.0" encoding="GB2312"?>
<project default="init" name="Project Argon">
<description>
A Simple project doing the nightly build in ant build file
</description>
<property name="sqlDir" location="sql"/>
<property name="logDir" location="log"/>
<property name="attachmentDir" location="attachment"/>
<tstamp>
<format property="creDate" pattern="yyyy-MM-dd"/>
</tstamp>
<!-- XML comments can also be used -->
<target name="init">
<mkdir dir="${sqlDir}"/>
<mkdir dir="${logDir}"/>
<mkdir dir="${attachment}"/>
<sql
driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@192.168.15.250:1521:ycdb"
userid="training"
password="deep1704sea"
src="./sql/queryData.sql"
showheaders="false"
print="yes"
output="${attachmentDir}/outputfile${creDate}.txt"
>
</sql>
<mail mailhost="email.ctgpc.com.cn" mailport="25" subject="TGPMS一周数据报告_${creDate}" charset="utf-8">
<from address="[email protected]"/>
<to address="[email protected]"/>
<message>您现在看到的是由系统发出的TGPMS一周数据报告.</message>
<fileset dir="${attachmentDir}">
<include name="*.txt"/>
</fileset>
</mail>
</target>
</project>
queryData.sql脚本如下:
SELECT 'Nightly Building begining: '||sysdate FROM dual;
SELECT '昨日D8512中新增'||COUNT(*)||'条工序编号' FROM process_no
WHERE modify_date>=sysdate-1;
SELECT '昨日D8512中新增'||COUNT(*)||'条指标编号' FROM process_test_index
WHERE modify_date>=sysdate-1;
本文地址:http://com.8s8s.com/it/it26829.htm