配合文章学习:
注意文章中有点问题,我在回复中提到
我按照楼主的建立
ant build, ant tests, ant deploy 也构建失败
而 target 填写: build, tests, deploy 就构建成功了
是不是因为新版本的问题??我用的ant-1.9.2版 jenkins是1.523
到了第二天,
学习 JUnit 加入集成测试,要点步骤如下:
重点是注意 target是执行的步骤,也就是上面配置Invoke Ant填得名称;
其次是注意deploy的部分,因为我的项目结构比较特殊,
1.在src/config有配置文件,所以需要copy
2.在项目中使用了Myeclipse插件,提供了JUnit提供的jar和J2ee提供的jar,这就需要自动部署的时候,手动copy
3.在考虑是直接部署还是打成war包部署,最终还是决定打成war包吧 这样移植的时候就不需要打包的步骤了,也会减少出错的可能
注:打包之后copy ,tomcat会自动检测war被更新因而会重新解压,发布应用。这样就会使得,项目中要是出现上传的图片或者添加的文件数据,就会被直接干掉。这点感觉很不好,所以解决方法有可以选择不打war包,或者把上传的文件夹和项目脱离放置。
build.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!-- =============================================
Auto unittest task and deploy application
Author: Winnid
Since: 20130723
============================================= -->
<project name="Meaningful-Framework" basedir="." default="profect">
<description> - Meaningful Framework 2.0 - </description>
<property file="build.properties"/>
<property name="appserver.deploy.name" value="mf2"/>
<property name="project.src" value="src"/>
<property name="project.test" value="test"/>
<property name="project.web" value="WebRoot"/>
<property name="project.lib" value="${project.web}/WEB-INF/lib"/>
<property name="project.lib.ant" value="${project.web}/WEB-INF/lib-ant"/>
<property name="project.build" value="${project.web}/WEB-INF"/>
<property name="build.src" value="${project.build}/classes" />
<property name="build.testcase" value="${project.build}/testcases" />
<property name="ant.report" value="${project.build}/report" />
<!-- - - - - - - - - - - - - - - - - -
set the depends jar files
- - - - - - - - - - - - - - - - - -->
<path id="master-classpath">
<fileset dir="${project.lib}" includes="**/*.jar"/>
<fileset dir="${project.lib.ant}" includes="**/*.jar"/>
<fileset dir="${appserver.lib}">
<include name="servlet*.jar"/>
</fileset>
</path>
<!-- - - - - - - - - - - - - - - - - -
target(1): folder init
- - - - - - - - - - - - - - - - - -->
<target name="init">
<mkdir dir="${ant.report}"/>
<mkdir dir="${build.src}"/>
<mkdir dir="${build.testcase}"/>
</target>
<!-- - - - - - - - - - - - - - - - - -
target(2.1): build src
- - - - - - - - - - - - - - - - - -->
<target name="build src" depends="init" description="Compile main source tree java files">
<javac srcdir="${project.src}" destdir="${build.src}"
encoding="utf-8" debug="on" deprecation="on"
optimize="on" failοnerrοr="true"
includeantruntime="on">
<classpath refid="master-classpath"/>
</javac>
<echo>build src complete!</echo>
</target>
<!-- - - - - - - - - - - - - - - - - -
target(2.2): build test
- - - - - - - - - - - - - - - - - -->
<target name="build test" depends="build src" description="Compile testcase source tree java files">
<javac srcdir="${project.src}" destdir="${build.src}"
encoding="utf-8" debug="on" deprecation="on"
optimize="on" failοnerrοr="true"
includeantruntime="on">
<classpath refid="master-classpath"/>
</javac>
<echo>build test complete!</echo>
</target>
<!-- - - - - - - - - - - - - - - - - -
target(2): build
- - - - - - - - - - - - - - - - - -->
<target name="build" depends="build src, build test" />
<!-- ========================================
target(3): auto test all test case and output report file
===================================== -->
<target name="junit and report" depends="build">
<junit printsummary="on" fork="true" showoutput="true">
<classpath>
<path refid="master-classpath"/>
<pathelement path="${build.src}"/>
<pathelement path="${build.testcase}"/>
</classpath>
<formatter type="xml" />
<batchtest todir="${ant.report}">
<fileset dir="${build.testcase}">
<include name="**/*Test*.*" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${ant.report}">
<fileset dir="${ant.report}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${ant.report}" />
</junitreport>
</target>
<!-- ========================================
target(4.1): deploy
===================================== -->
<target name="deploy" depends="junit and report" description="Deploy application">
<!-- copy 项目文件 -->
<copy todir="${appserver.deploy.path}/${appserver.deploy.name}" preservelastmodified="true">
<fileset dir="${project.web}">
<include name="**/*.*"/>
<exclude name="**/lib-ant/*.*" />
</fileset>
</copy>
<!-- copy 项目ant中的jar -->
<copy todir="${project.web}/WEB-INF/lib" includeemptydirs="false">
<fileset dir="${project.lib.ant}">
<include name="**/*.jar"/>
</fileset>
</copy>
<!-- copy 项目src中的config -->
<copy todir="${appserver.deploy.path}/${appserver.deploy.name}/WEB-INF/classes" includeemptydirs="false">
<fileset dir="${project.src}">
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
<!-- ========================================
target(4.2): deploy war
===================================== -->
<target name="deploywar" depends="junit and report" description="Deploy application as a WAR file">
<!-- copy 项目src中的config -->
<copy todir="${project.web}/WEB-INF/classes" includeemptydirs="false">
<fileset dir="${project.src}">
<exclude name="**/*.java" />
</fileset>
</copy>
<!-- copy 项目ant中的jar -->
<copy todir="${project.web}/WEB-INF/lib" includeemptydirs="false">
<fileset dir="${project.lib.ant}">
<include name="**/*.jar"/>
</fileset>
</copy>
<!-- 项目文件打war包 -->
<war destfile="${appserver.deploy.name}.war"
webxml="${project.web}/WEB-INF/web.xml">
<fileset dir="${project.web}">
<include name="**/*.*"/>
<exclude name="**/lib-ant/*.*" />
</fileset>
</war>
<!-- copy war包 到Tomcat -->
<copy todir="${appserver.deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<target name="clean" description="Deletes compiled and generated code">
<!-- <delete dir="${project.build}"/>
<delete dir="${ant.report}"/> -->
</target>
<target name="profect" depends="init, build, junit and report, deploywar, clean"/>
</project>
中间出现了很多错误,内存也有溢出的时候,因为我用的是奔4的机子内存1.5。。。。
EasyAnt 看不懂的新插件,貌似不能集成到现在用的项目中,而且更新时间是2010年,哎。。。
下面 还要继续学习的是 build.xml更加自动化。主要是findbug!!!
另外Jenkins有强大的插件集成,目前还在学习中。
但是由于下一个项目,是要用Android框架,所以开始探索
Jenkins学习笔记(十一)如何构建和测试Android app