怎樣用Ant測試Spring項目
一、可以運行,但是要設(shè)置Eclipse,以使Eclipse自動往我的 <property name="run.classpath" value="${home.dir}/bin"></property> 中復(fù)制Spring配置文件。 <?xml version="1.0"?> <!-- 設(shè)置了路徑以后就正常了 Eclipse中,,java構(gòu)建路徑.java源:src,test,WebRoot; 缺省輸出文件夾 為/bin 這個目錄,否則會報Spring的bean未定義錯誤,! 原因就是因為Spring配置文件無法在classpath中找到,! --> <project name="project" default="junit"> <!-- chu shi hua , ti gong huan jing bian liang deng zhun bei --> <target name="init">
<property name="home.dir" value="."/>
<property name="run.classpath" value="${home.dir}/bin"></property>
<!-- <property name="run.classpath" value="${home.dir}/build/classes"></property> --> <property name="run.srcpath" value="${home.dir}/src"></property>
<property name="test.report" value="${home.dir}/report"></property> <!-- <property name="test.config" value="${home.dir}/WebRoot"></property> --> <property name="lib.dir" value="${home.dir}/lib"/>
<include name="**/*.jar"/> </fileset>
</target> <!-- Compilation Classpath <path id="compile.classpath"> <fileset dir="${telecom_LDBS.lib}"> <include name="**/*.jar"/> </fileset> </path> -->
<!-- Compile ,wei JUnit ti gong .class wen jian. zai jia shang yu xian ti gong de jar zhong de .class wen jian , ji ke yun xing JUnit. dang ran, hai xu yao junit.jar he ant-junit.jar(huo optional.jar) he ant.jar zhe 3 ge jar bao de zhi chi --> <target name="compile" depends="init">
<!-- junit renwu, zhi xing junit ce shi . bie wang le,classpath ,the classpath to use. xu yao zhi ding classpath yuansu ,ta bao kuo compile lu jing,he bian yi de jie gou classpath (bao kuo sheng cheng de suo you .class wen jian) --> <target name="junit" depends="compile">
<mkdir dir="${test.report}"/> <mkdir dir="${test.report}/framework-${DSTAMP}-${TSTAMP}"/>
<junit printsummary="true">
<pathelement path="${run.classpath}"/> <!-- <pathelement path="${test.config}"/> --> <fileset dir="${lib.dir}"> <include name="**/*.jar"/> </fileset>
</classpath>
<!-- <test name="Ldbs1AdslSectionBaseinfoModelServiceTest"></test> --> <formatter type="plain"/> <!-- she zhi yao ce shi de wen jian ji he .--> <batchtest fork="yes" todir="${test.report}/framework-${DSTAMP}-${TSTAMP}"> <fileset dir="${test.srcpath}"> <include name="**/*Test.java"/>
</fileset> </batchtest>
<!-- =============================== all ==================================== --> <target name="all" depends="junit" /> </project>
<?xml version="1.0"?>
<!-- chu shi hua , ti gong huan jing bian liang deng zhun bei -->
<target name="init">
<property name="home.dir" value="."/>
<property name="test.war" value="${home.dir}/build/war"></property>
<property name="run.classpath" value="${home.dir}/build/war/WEB-INF/classes"></property>
<!--
<property name="run.classpath" value="${home.dir}/build/classes"></property>
-->
<property name="run.srcpath" value="${home.dir}/src"></property>
<property name="test.report" value="${home.dir}/report"></property>
<property name="test.config" value="${home.dir}/WebRoot"></property>
<property name="lib.dir" value="${home.dir}/lib"/>
<include name="**/*.jar"/>
</fileset>
</target>
<!-- Compilation Classpath
<path id="compile.classpath">
<fileset dir="${telecom_LDBS.lib}">
<include name="**/*.jar"/>
</fileset>
</path>
-->
<!-- Compile ,wei JUnit ti gong .class wen jian. zai jia shang yu xian ti gong de
jar zhong de .class wen jian , ji ke yun xing JUnit.
dang ran, hai xu yao junit.jar he ant-junit.jar(huo optional.jar) he ant.jar zhe 3 ge jar bao de zhi chi
-->
<target name="compile" depends="init">
<target name="war" depends="compile">
<mkdir dir="${test.war}/WEB-INF"/>
<mkdir dir="${test.war}/WEB-INF/classes/config/db"/>
<mkdir dir="${test.war}/WEB-INF/classes/config/acl"/>
<copy todir="${test.war}">
<fileset dir="${test.config}" excludes="**/vssver.scc">
<include name="**/*.*"/>
<exclude name="**/vssver.scc"/>
<exclude name="**/build.xml"/>
<exclude name="**/build.properties"/>
<exclude name="**/targets.xml"/>
</fileset>
</copy>
<copy todir="${test.war}/WEB-INF/classes/config/db">
<fileset dir="${telecom_LDBS.config}/db">
</fileset>
</copy>
<copy todir="${test.war}/WEB-INF/classes/config/acl">
<fileset dir="${telecom_LDBS.config}/acl">
<include name="*.xml" />
<exclude name="**/vssver.scc" />
</fileset>
</copy>
<!-- junit renwu, zhi xing junit ce shi . bie wang le,classpath ,the classpath to use.
xu yao zhi ding classpath yuansu ,ta bao kuo compile lu jing,he bian yi de jie gou classpath
(bao kuo sheng cheng de suo you .class wen jian)
-->
<target name="junit" depends="war">
<mkdir dir="${test.report}"/>
<mkdir dir="${test.report}/framework-${DSTAMP}-${TSTAMP}"/>
<junit printsummary="true">
<pathelement path="${test.war}"/>
<pathelement path="${run.classpath}"/>
<!--
<pathelement path="${test.config}"/>
-->
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</classpath>
<!--
<test name="Ldbs1AdslSectionBaseinfoModelServiceTest"></test>
-->
<formatter type="plain"/>
<!-- she zhi yao ce shi de wen jian ji he .-->
<batchtest fork="yes" todir="${test.report}/framework-${DSTAMP}-${TSTAMP}">
<fileset dir="${test.srcpath}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
<!-- =============================== all ==================================== -->
<target name="all" depends="junit" />
</project>
也就是說,,現(xiàn)在,classpath中由3部分組成: 1,,jar文件集 2,,.class文件集 3,Spring,、Hibernate等配置文件集,。 實際上,我們也可以進(jìn)一步改進(jìn),。將JUnit任務(wù)和發(fā)布war包的任務(wù)合在一起,。
<!-- $Id: build.xml,v 1.3 2004/02/08 09:04:42 cvs Exp $ -->
<!-- =================================================================== -->
<target name="init">
<!-- change this property to use a compiler other than javac. -->
<property name="build.compiler" value="modern"/>
<property name="telecom_LDBS.home" value="."/>
<property name="telecom_LDBS.lib" value="${telecom_LDBS.home}/lib"/>
<property name="telecom_LDBS.src" value="${telecom_LDBS.home}/src"/>
<!-- The destination directory for the build -->
<property name="telecom_LDBS.build" value="${telecom_LDBS.home}/build"/>
<property name="telecom_LDBS.buildconfigdir" value="${telecom_LDBS.home}/build/config"/>
<property name="telecom_LDBS.buildwardir" value="${telecom_LDBS.home}/build/war"/>
<property name="telecom_LDBS.buildeardir" value="${telecom_LDBS.home}/build/ear"/>
<property name="telecom_LDBS.classbindir" value="${telecom_LDBS.build}/classes"/>
<property name="telecom_LDBS.srcdocroot" value="${telecom_LDBS.home}/WebRoot"/>
<property name="telecom_LDBS.config" value="${telecom_LDBS.srcdocroot}/WEB-INF/classes/config"/>
<property name="test.report" value="${telecom_LDBS.home}/report"></property>
<property name="test.srcpath" value="${telecom_LDBS.home}/test"></property>
<!-- ^ junit tina jia-->
<!-- Compilation Classpath -->
<path id="compile.classpath">
<fileset dir="${telecom_LDBS.lib}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- The destination appServer for War. -->
<property name="tomcat.deployhome" value="D:\java\tomcat\webapps"/>
<property name="tomcat.deploywar" value="${tomcat.deployhome}\telecom_LDBS_ADSL"/>
<target name="compile" depends="init">
<echo message="${telecom_LDBS.classpath}" />
<mkdir dir="${telecom_LDBS.classbindir}"/>
<javac srcdir="${telecom_LDBS.src}"
destdir="${telecom_LDBS.classbindir}"
includes="com/**"
debug="yes">
<classpath refid="compile.classpath"/>
</javac>
<copy file="${telecom_LDBS.src}/com/telecom/ldbs/common/util/ApplicationResources_ISO.properties"
tofile="${telecom_LDBS.src}/com/telecom/ldbs/common/util/ApplicationResources.properties"/>
<native2ascii encoding="gb2312" src="${telecom_LDBS.src}" dest="${telecom_LDBS.classbindir}"
includes="**/*Resources.properties"/>
<fileset dir="${telecom_LDBS.src}">
<include name="**/*_ISO.properties"/>
<include name="**/*Methods.properties"/>
</fileset>
</copy>
<fileset dir="${telecom_LDBS.src}">
</fileset>
</copy>
</target>
<target name="war" depends="init">
<mkdir dir="${telecom_LDBS.buildwardir}/WEB-INF"/>
<mkdir dir="${telecom_LDBS.buildwardir}/WEB-INF/classes/config/db"/>
<mkdir dir="${telecom_LDBS.buildwardir}/WEB-INF/classes/config/acl"/>
<copy todir="${telecom_LDBS.buildwardir}">
<fileset dir="${telecom_LDBS.srcdocroot}" excludes="**/vssver.scc">
<include name="**/*.*"/>
<exclude name="**/vssver.scc"/>
<exclude name="**/build.xml"/>
<exclude name="**/build.properties"/>
<exclude name="**/targets.xml"/>
</fileset>
</copy>
<copy todir="${telecom_LDBS.buildwardir}/WEB-INF/lib">
<fileset dir="${telecom_LDBS.lib}">
<include name="**/*.jar"/>
<exclude name="**/vssver.scc" />
<exclude name="**/servlet.jar" />
<exclude name="**/j2ee.jar" />
</fileset>
</copy>
<copy todir="${telecom_LDBS.buildwardir}/WEB-INF/classes">
<fileset dir="${telecom_LDBS.classbindir}">
<include name="**/**.class" />
<include name="**/**.properties" />
<exclude name="**/vssver.scc" />
</fileset>
</copy>
<copy todir="${telecom_LDBS.buildwardir}/WEB-INF/classes">
<fileset dir="${telecom_LDBS.srcdocroot}/WEB-INF/menu">
<include name="**/**.vm" />
</fileset>
</copy>
<copy todir="${telecom_LDBS.buildwardir}/WEB-INF/classes/config/db">
<fileset dir="${telecom_LDBS.config}/db">
</fileset>
</copy>
<copy todir="${telecom_LDBS.buildwardir}/WEB-INF/classes/config/acl">
<fileset dir="${telecom_LDBS.config}/acl">
<include name="*.xml" />
<exclude name="**/vssver.scc" />
</fileset>
</copy>
<target name="deploy" depends=" compile, war">
<mkdir dir="${tomcat.deploywar}" />
<fileset dir="${telecom_LDBS.buildwardir}">
<include name="**/**.*"/>
</fileset>
</copy>
</target>
<copy todir="${tomcat.deploywar}">
<fileset dir="${telecom_LDBS.srcdocroot}">
<include name="**/*.jsp"/>
<include name="**/*.inc"/>
<include name="**/*.xml"/>
<include name="**/*.js"/>
<include name="**/*.htm*"/>
</fileset>
</copy>
</target>
<target name="deploy_all" depends="init">
<copy todir="${tomcat.deploywar}">
<fileset dir="${telecom_LDBS.srcdocroot}">
<include name="**/*.jsp"/>
<include name="**/*.inc"/>
<include name="**/*.xml"/>
<include name="**/*.js"/>
<include name="**/*.htm*"/>
<include name="**/*.class"/>
<include name="**/*.properties"/>
</fileset>
</copy>
</target>
<target name="clean" depends="init">
<mkdir dir="${telecom_LDBS.build}" />
<mkdir dir="${tomcat.deploywar}" />
<delete includeEmptyDirs="true">
<fileset dir="${telecom_LDBS.build}" includes="**/**"/>
</delete>
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${tomcat.deployhome}/telecom_LDBS" includes="**/**"/>
</delete>
</target>
<!-- junit tina jia-->
<!-- junit renwu, zhi xing junit ce shi . bie wang le,classpath ,the classpath to use.
xu yao zhi ding classpath yuansu ,ta bao kuo compile lu jing,he bian yi de jie gou classpath
(bao kuo sheng cheng de suo you .class wen jian)
-->
<target name="junit" depends="war">
<mkdir dir="${test.report}"/>
<mkdir dir="${test.report}/framework-${DSTAMP}-${TSTAMP}"/>
<junit printsummary="true">
<pathelement path="${telecom_LDBS.buildwardir}"/>
<pathelement path="${telecom_LDBS.classbindir}"/>
<!--
<pathelement path="${test.config}"/>
-->
<fileset dir="${telecom_LDBS.lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
<!--
<test name="Ldbs1AdslSectionBaseinfoModelServiceTest"></test>
-->
<formatter type="plain"/>
<!-- she zhi yao ce shi de wen jian ji he .-->
<batchtest fork="yes" todir="${test.report}/framework-${DSTAMP}-${TSTAMP}">
<fileset dir="${test.srcpath}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
<!-- ^ junit tina jia-->
<!-- =============================== all ==================================== -->
<target name="all" depends=" clean, compile, war ,junit"/>
</project>
本文來自CSDN博客,轉(zhuǎn)載請標(biāo)明出處:http://blog.csdn.net/shendl/archive/2005/11/18/532592.aspx |
|