Java中自动化集成

Java中自动化集成

JavaYangJoke 2004.06.28

概述

       项目从开始到结束都离不开重复各种步骤以达到单元测试、集成测试,特别是NNweb应用程序中,下面我是在Java web程序开发中持续集成的一点点。

 

1、  ANThttp://ant.apache.org/

Ant apache 中的一个开源项目,是一个相当简单的Build工具。

l         安装

n         http://ant.apache.org/bindownload.cgi下载

n         解压下载后的文件,在操作系统中设置环境变量(ANT_HOME=${ANT_HOME}

n         并在path中加入PATH=PATH;ANT_HOME/bin

l         使用

n         写一个build.xml文件(见下面)

n         CMD窗口中运行ant –f  build.xml

 

一个简单的Build.xml文件

<?xml version="1.0" encoding="ISO-8859-1"?>

<!—default为默认执行的任务à

<project name="project name" default=" ftp_task" basedir=".">

<property name="ant.home " value="/usr/lib" />

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

<!--Define a ftp task! Use NetComponents.jar                        -->

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

 

<!—自定义任务-->

       <target name="defineTasks" depends="properties">

         <taskdef name="ftp"

classname="org.apache.tools.ant.taskdefs.optional.net.FTP"             classpath="${ ant.home }/optional.jar:${ ant.home }/ NetComponents.jar "

 />

       </target>

 

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

<!-- Put files to the ftp Server                         -->

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

<!—执行任务-->

 

       <target name="ftp_task" depends="defineTasks"  description="--> makes a complete hyaq release">

              <ftp action="put"

                 server="server ip"

                 userid="user name"

                 password="password"

port="9997"

                 >  

                     <fileset dir="${dir}">

                             <include name="file.war"/>

                      </fileset>

              </ftp>

       </target>      

</project>

 

2、  XDoclethttp://xdoclet.sourceforge.net/xdoclet/index.html

Xdoclet也是sourceforge中一个开源项目,它主要用在生成描述文件,他包括好多个流得框架配置文件的生成。在写代码就可以直接写出文件的相关描述信息,也可以先把各种类型的配置信息单独放在一个文件里,最后由Xdoclet生成。使用时也可以用它自定义的ANT功能,也可以用命令行的方式。

 

一个简单的例子

 

java:

 

package com.alt.gzcx.action;

 

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpSession;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/** 

*     @web.servlet

*            name="FileDownloadAction"

*            display-name="File Download Action"

*            description="File Download Action"

*            load-on-startup="1"

*

*     @web.servlet-mapping

*            url-pattern="file/FileDownloadAction"

*/

 

public class FileDownloadAction extends HttpServlet {

       public void init(ServletConfig config)

              throws ServletException{

       }

       public void service(HttpServletRequest request, HttpServletResponse response)

              throws ServletException, java.io.IOException {

       }

}

 

 

<?xml version="1.0" encoding="ISO-8859-1"?>

 

<project name="Gzcx" default="webdoclet" basedir=".">

       <property name="gzcx.root.dir" value="f:/gzcx"/>

       <property name="java.dir" value="${gzcx.root.dir}/src"/>

       <property name="dest.dir" value="${gzcx.root.dir}/dest"/>

       <property name="web.dir" value="${gzcx.root.dir}/webapps/gzcx"/>

       <property name="web.web-inf.dir" value="${gzcx.root.dir}/webapps/gzcx/WEB-INF"/>

       <property name="web.lib.dir" value="f:/resin/lib"/>

       <property name="xdoclet.lib.dir" value="F:/study/xdoclet/xdoclet-1.2.1/lib"/>

 

   

       <!-- Define the class path                                               -->

  

       <path id="class.path">

              <fileset dir="${web.lib.dir}">

                     <include name="*.jar"/>

              </fileset>

              <fileset dir="${xdoclet.lib.dir}">

                     <include name="*.jar"/>

              </fileset>

       </path>         

      

    

       <!-- Initialise                                                          -->

  

       <target name="init">

              <tstamp>

                     <format property="TODAY" pattern="d-MM-yy"/>

              </tstamp>

              <taskdef

                     name="xdoclet"

                     classname="xdoclet.DocletTask"

                     classpathref="class.path"

                     />

              <taskdef

                     name="ejbdoclet"

                     classname="xdoclet.modules.ejb.EjbDocletTask"

                     classpathref="class.path"

                     />

              <taskdef

                     name="webdoclet"

                     classname="xdoclet.modules.web.WebDocletTask"

                     classpathref="class.path"

                     />

              <taskdef

                     name="jmxdoclet"

                     classname="xdoclet.modules.jmx.JMXDocletTask"

                     classpathref="class.path"

                     />

              <taskdef

                     name="jdodoclet"

                     classname="xdoclet.modules.jdo.JdoDocletTask"

                     classpathref="class.path"

                     />

              <taskdef

                     name="hibernatedoclet"

                     classname="xdoclet.modules.hibernate.HibernateDocletTask"

                     classpathref="class.path"

                     />

       </target>

      

       <target name="generate"

        description="Generates Hibernate class descriptor files."

        depends="init">

 

           <!-- Execute the hibernatedoclet task -->

           <hibernatedoclet

               destdir="${web.web-inf.dir}/classes"

            mergedir="${web.web-inf.dir}/classes"

               >

          

               <fileset dir="${java.dir}">

                   <include name="**/*Bean.java"/>

               </fileset>

          

               <hibernate/>

          

           </hibernatedoclet>

      

           <!-- Upgrade grammar from Hibernate1 to Hibernate2 -->

           <replace dir="${web.web-inf.dir}/classes">

               <include name="**/hibernate/*.hbm.xml"/>

               <replacefilter token="readonly=" value="inverse="/>

               <replacefilter token="role=" value="name="/>

               <replacefilter token="hibernate-mapping.dtd" value="hibernate-mapping-2.0.dtd"/>

           </replace>

       </target>

 

       <!-- Invoke XDoclet's webdoclet                                          -->

    

       <target name="webdoclet" depends="init">

             

              <echo>+---------------------------------------------------+</echo>

              <echo>|                                                   |</echo>

              <echo>| R U N N I N G   W E B D O C L E T                 |</echo>

              <echo>|                                                   |</echo>

              <echo>+---------------------------------------------------+</echo>

             

              <webdoclet

                     destdir="${dest.dir}"

                     mergedir="parent-fake-to-debug"

                     excludedtags="@version,@author,@todo"

                     addedtags="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}"

                     force="false"

                     verbose="false"

                     >

                    

                     <fileset dir="${java.dir}">

                            <include name="**/*Servlet.java"/>

                            <include name="**/*Filter.java"/>

                            <include name="**/*Tag.java"/>

                            <include name="**/*Action.java"/>

                     </fileset>

                    

                     <deploymentdescriptor

                            servletspec="2.3"

                            destdir="${web.web-inf.dir}"

                            >

                           

                     </deploymentdescriptor>

                    

              </webdoclet>

       </target>

      

</project>

 

ant –f xdoclet.xml就可以生成了。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值