分享

appfuse配置文件解读

 duduwolf 2006-09-30
● AppFuse的ant构建使用非常复杂,功能也非常强大,怎样能够充分的利用它,为我所用,在今后的开发中大幅度的减轻开发量,顾做此详细研究(其中不包括测试任务)。 build.xml的正常运行依赖以下文件i) propertie..

    AppFuse的ant构建使用非常复杂,功能也非常强大,

怎样能够充分的利用它,为我所用,在今后的开发中大幅度的减轻开发量,顾做此详细研究(其中不包括测试任务)。

 

 

Ø build.xml的正常运行依赖以下文件

i)                 properties.xml

该文件定义build.xml所需的属性值,主要完成通过build.properties 产生

database.properties 文件定义构建工具需要的Classpath属性等工作。

 

 

ii)                app-settings.xml

该文件定义设置应用程序状态的一些属性值

 

 

iii)              build.properties

定义一些全局设置属性

 

 

Ø build.xml文件具体分析

<!DOCTYPE project [

    <!ENTITY properties SYSTEM "properties.xml">

    <!ENTITY app-settings SYSTEM "app-settings.xml">

]>

<!XML DTD定义propertiesapp-settings -->

<project name="dudu" basedir="." default="package-web">

    <!导入配置文件properties.xml(其中主要处理classpath,jar文件位置定义)-->

    <!-- import project-wide properties (classpath, jar file locations) -->

    &properties;

    <!导入配置文件app-settings.xml-->

    &app-settings;

    <!定义一些自定义任务,-->

    <target name="init" description="defines custom tasks">

       

    </target>

    <!建立所需的目录:build/dudu;build/dudu/WEB-INF;dist/webapps-->

    <target name="prepare" depends="build.properties.missing,init"

       

    </target>

    <!用定义的名字新建一个项目 -->

    <!使用方法ant new -Dapp.name=NAME -Ddb.name=NAME -->

    <!该任务会在上层目录中构建自定义名字应用程序,内容与本目录中的大致相同-->

    <target name="new" depends="clean">

       

    </target>

 

 

<!拷贝资源和配置文件:将web/WEB-INF/classes下的ApplicationResources_zh_CN.properties;log4j.properties等配置文件拷贝到build/web/classes下.

    拷贝src/dao/packageName/applicationContext-hibernate.xml 到dudu/WEB-INF目录下,

    拷贝src/service/packageName/applicationContext-service.xml到dudu/WEB-INF目录下.

在此任务中会进行native2ascii 的转码工作.

此任务比较有用,以后可以复用.

-->

    <target name="copy-resources" depends="prepare">

        <native2ascii src="http://dev.csdn.net/article/"web/WEB-INF/classes""

            dest="${build.dir}/web/classes"

            includes="ApplicationResources_zh_CN.properties" encoding="gb2312"/>

    </target>

   

    <!拷贝web目录下footer.jsp; pages/*.jsp;**/classes/**;**/*-resources.xml到

        build/dudu/的对应目录下,拷贝时会自动建立相应的目录结构

-->

    <target name="copy-web-files" depends="prepare">

      

    </target>

   

    <!拷贝所有页面与配置文件以形成web应用程序-->

    <target name="stage-web"

        depends="copy-resources,copy-web-files"

        description="Calls other targets to gather static resources"/>

       

  

    <!利用XDoclet根据POJO生成对应的hiberante映射文件

        根据src/dao中的POJO生成映射文件,存放于build/dao/gen目录中.

此任务比较有用,以后可以复用.

执行此任务之前,需执行ant clean删除build目录

-->

    <target name="hibernatedoclet" depends="prepare"

        unless="hibernatedoclet.unnecessary"

        description="Generate Hibernate mapping files">

        <taskdef name="hibernatedoclet"

            classname="xdoclet.modules.hibernate.HibernateDocletTask"

            classpathref="http://dev.csdn.net/article/"xdoclet.classpath"/>

        <!-- generate hibernate files -->

        <hibernatedoclet

            destdir="${build.dir}/dao/gen"

            mergedir="metadata/dao"

            excludedtags="@version,@author"

            addedtags="@xdoclet-generated at ${TODAY}"

            force="${xdoclet.force}">

            <fileset dir="src/dao"/>

            <hibernate validatexml="true" version="2.0"/>

        </hibernatedoclet>

    </target>

 

 

<!编译dao模块-->

    <target name="compile-dao" depends="hibernatedoclet">

       

    </target>

 

 

    <!将编译好的dao模块打包成对应的jar文件,生成的jar文件存放在dist目录下-->

    <target name="package-dao" depends="prepare,compile-dao"

      

    </target>

 

 

    <!编译service模块-->

    <target name="compile-service" depends="package-dao"

        description="Compile service module">

        <antcall target="compile-module" inheritAll="true">

            <param name="module" value="service"/>

            <reference refid="service.compile.classpath"

                torefid="http://dev.csdn.net/article/"compile.classpath"/>

            <reference refid="service.test.classpath"

                torefid="test.classpath"/>

        </antcall>

    </target>

 

 

    <!打包service模块,日后开发自定义的模块可以参考此任务编译和打包-->

    <target name="package-service" depends="compile-service">

        <jar destfile="${dist.dir}/${webapp.name}-service.jar">

            <manifest>

                <attribute name="Class-Path"

                    value="${webapp.name}-dao.jar ${webapp.name}-service.jar"/>

            </manifest>

            <fileset dir="${build.dir}/service/classes" includes="**/*.class"/>

        </jar>

    </target>

 

 

    <!根据POJO生成Struts 的ActionForms,生成的FormBean存放在build/web/gen下

        此任务比较有用,以后可以复用

 -->

    <target name="gen-forms" depends="prepare" unless="webdoclet.uptodate">

       

    </target>

 

 

    <!利用webdoclet生成web.xml;struts-config.xml等web应用程序配置文件

        生成的文件放在build/dudu/WEB-INF下

        此任务比较有用,以后可以复用

-->

    <target name="webdoclet" depends="compile-web"

        unless="webdoclet.unnecessary">

        

    </target>

  

    <!打包web模块,处理build/dudu/WEB-INF/web.xml文件;

根据metadata/conf/tomcat-context.xml 产生dist/webapps/context.xml;

改变build/dudu/WEB-INF/ applicationContext-hibernate.xml中的路径,以便

        dudu-dao.jar可以找到.hbm文件,

拷贝src/web/**/*.properties和*.xml文件到build/web/classes中,

将build/dudu下的文件打包成dist/dudu.war,其中包括build/web/classes中的文件

生成WEB-INF/classes中的文件,

dist/*.jar生成WEB-INF/lib中的文件

此任务比较有用,以后可以复用

-->

    <target name="package-web" depends="compile-web,jsp-2">

       

    </target>

  

    <!所有编译任务都要调用的基本编译,接收其他任务的参数,编译相应的模块

        输入参数:待编译模块名称,编译所需的路径.

        编译后的文件存放于build/moduleName/classes中.

        此任务比较有用,以后可以复用

-->

    <target name="compile-module">

        <!-- Inputs: module, compile.classpath, test.classpath -->

        <echo level="info">Compiling ${module}...</echo>

        <mkdir dir="${build.dir}/${module}/classes"/>

        <mkdir dir="${test.dir}/${module}/classes"/>

        <property name="excludes" value=""/>

        <property name="additional.src.dirs" value=""/>

        <javac srcdir="src/${module};${additional.src.dirs}"

            destdir="${build.dir}/${module}/classes"

            debug="${compile.debug}"

            deprecation="${compile.deprecation}"

            optimize="${compile.optimize}"

            classpathref="http://dev.csdn.net/article/"compile.classpath"/>

    </target>

    <!

将数据库中的数据导出为xml文件

    此任务比较有用,以后可以复用

-->

    <target name="db-export" depends="prepare"

       

    </target>

   

    <!利用dbunit工具,根据metadata/sql/sample-data.xml 填充数据库表记录-->

   <target name="db-load" depends="prepare"

     

    </target>

    <!

根据metadata/sql/${database.type}-create.sql中的sql语句建立数据库和用户

此任务比较有用,以后可以复用

-->

    <target name="db-create" depends="init">

       

    </target>

   

    <!

根据映射hibernate映射文件生成数据库表

此任务比较有用,以后可以复用

-->

    <target name="db-prepare" depends="clean,package-dao"

        description="creates database tables">

        <taskdef name="schemaexport"

            classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">

            <classpath>

                <path refid="xdoclet.classpath"/>

                <path refid="hibernate.classpath"/>

            </classpath>

        </taskdef>

        <antcall target="generate.database.properties"/>

        <schemaexport quiet="no" text="no" drop="no" delimiter=";"

            properties="database.properties" output="create-tables.sql">

            <fileset dir="${build.dir}/dao/gen" includes="**/*.hbm.xml"/>

        </schemaexport>

    </target>

 

 

    <!删除数据库中的表-->

<target name="db-drop" depends="hibernatedoclet">

   

    </target>

       

    <!删除目录-->

    <target name="clean" description="Removes build artifacts">

        <delete dir="${build.dir}"/>

    </target>

 

 

    <!生成JavaDoc,生成文件存放在E:\dudu\build\docs\api -->

    <target name="javadoc" depends="java2html">

       

    </target>

  

    <!

将build/dudu下的文件拷贝到tomcat-home/webapps/dudu/,包括完整的目录和所有的

Jsp文件,但不包括jar文件和WEB-INF/classes中的文件,也不包括web.xml文件和

spring的配置文件这些文件不在build/dudu目录下.

-->

    <target name="deploy-web" depends="stage-web" if="tomcat.home">

       

    </target>

    <!部署web应用,并解包war文件-->

    <target name="deploy" depends="package-web" if="tomcat.home">

        <unwar src="http://dev.csdn.net/article/"${webapp.dist}/${webapp.war}"

            dest="${tomcat.home}/webapps/${webapp.name}"/>

    </target>

    <!删除web应用 -->

    <target name="undeploy" if="tomcat.home">

        <delete file="${tomcat.home}/webapps/${webapp.war}"/>

        <delete dir="${tomcat.home}/webapps/${webapp.name}"/>

    </target>

 

 

    <!将war文件拷贝到tomcat容器-->

    <target name="deploy-war" depends="package-web" if="tomcat.home">

        <copy file="${webapp.dist}/${webapp.war}"

            todir="${tomcat.home}/webapps"/>

    </target>

   </project>

 

 

Ø properties.xml文件分析

该文件定义build.xml所需的属性值。

<!导入lib.properties 文件,其中包括了构建时所需的jar文件定义-->

<property name="lib.dir" location="lib"/>

<property file="${lib.dir}/lib.properties"/>

<!加载build.properties 文件-->

<property file="build.properties"/>

<!加载运行unit tests所需的tomcat配置属性文件 -->

<property file="tomcat.properties"/>

<!-- webapp.name被定义在build.properties,在此做检查看该属性是否被定义-->

<target name="build.properties.missing" unless="webapp.name">

    <fail message="missing build.properties file in current directory or in ${user.home}"/>

</target>

<!如果build.properties 不存在时,定义数据库的基本配置-->

<property name="database.jar" location="${mysql.jar}"/>

<!定义建立数据库时所用到的database URL,它被用在db-create任务中-->

<property name="database.url"

    value="jdbc:mysql://localhost/jpetstore"/>

<!通过build.properties 产生database.properties 文件-->

<!由于build.properties 中的属性被注释了,所以这些属性会从properties.xml中取得-->

<target name="generate.database.properties">

    <propertyfile comment="Hibernate Configuration for JUnit tests"

        file="${basedir}/database.properties">

        <entry key="hibernate.dialect" value="${hibernate.dialect}"/>

       

     </propertyfile>

</target>

<!初始化属性值-->

<property environment="env"/>

<property name="env.COMPUTERNAME" value="${env.HOSTNAME}"/>

<!properties.xml文件的主要工作:定义构建工具需要的Classpath属性-->

<path id="xdoclet.classpath">

   

</path>

<path id="hibernate.classpath">

</path>

<path id="dao.compile.classpath">

   

</path>

<path id="dao.test.classpath">

</path>

<path id="service.compile.classpath">

</path>

<path id="service.test.classpath">

   

</path>

<path id="web.compile.classpath">

   

</path>

<path id="web.test.classpath">

   

</path>

  

Ø app-settings.xml文件分析

该文件定义设置应用程序状态的一些属性值

<property name="encrypt.password" value="true"/>

<property name="encrypt.algorithm" value="SHA"/>

<property name="secure.login" value="false"/>

<property name="secure.application" value="false"/>

<property name="rememberMe.enabled" value="true"/>

 

 

Øbuild.properties文件分析

build.compiler=modern

webapp.name=dudu

webapp.version=1.7

webapp.war=${webapp.name}.war

compile.deprecation=true

build.dir=${basedir}/build

dist.dir=${basedir}/dist

test.dir=${build.dir}/test

javac.debug=true

junit.fork=true

xdoclet.force=false

error.mailTo=junk@raibledesigns.com

error.mailHost=localhost

error.server=localhost

ftp.server=upload.sourceforge.net

ftp.remoteDir=incoming

ftp.user=anonymous

Ø tomcat.properties文件分析

tomcat.server=localhost

tomcat.manager.url=http://${tomcat.server}:8080/manager

tomcat.username=admin

tomcat.password=admin


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多