ofbiz的ant命令创建模块

1.简介说明

       一般我们在hot-deploy下部署应用是,可以通过ant的create-component这个命令来创建,这种方法的好处是自动创建的会节省自己很多时间,并且避免一些不必要的错误,下面就从简述一下ant构建,以及模块的创建

      声明:禁止转载,不是因为文章好不好,而是对于百度搜索,一搜一大片一样,很烦

2.软件版本

     ofbiz-trunk

3.ant命令

     ant是一种自动构建工具,其环境配置跟java环境差不多,配置全局变量后,运行xml文件对应的target就可以执行相关的操作。

     但ant不是我主要要讲的东西,只简要介绍一些基本语法:

     target:是一个容器,指令集合,一个事务

     copy:拷贝单个文件到指定路径

delete:删除文件

     参考资料:http://blog.csdn.net/linchaolong/article/details/45057257

4.模块创建

     运行buil.xmld下的create-component,而后输入对应值

      然后 击ok对应的模块就会创建出来,文件结构效果如下:

|____build.xml
|____config
| |____resourec-nameUiLabels.xml
|____data
| |____helpdata
| | |____HELP_resourec-name.xml
| |____resourec-nameDemoData.xml
| |____resourec-nameSecurityGroupDemoData.xml
| |____resourec-nameSecurityPermissionSeedData.xml
| |____resourec-nameTypeData.xml
|____documents
| |____resourec-name.xml
|____dtd
|____entitydef
| |____entitymodel.xml
|____lib
|____ofbiz-component.xml
|____patches
| |____production
| |____qa
| |____test
|____script
|____servicedef
| |____services.xml
|____src
|____testdef
| |____resourec-nameTests.xml
|____webapp
| |____webapp-name
| | |____error
| | | |____error.jsp
| | |____index.jsp
| | |____WEB-INF
| | | |____actions
| | | |____controller.xml
| | | |____web.xml
|____widget
| |____CommonScreens.xml
| |____resourec-nameForms.xml
| |____resourec-nameMenus.xml
| |____resourec-nameScreens.xml

5.create- component命令简述

<target name="create-component"
        description="Create the layout of an OFBiz component in the hot-deployfolder.">
    <!--提供组件名资源文件名等输入文本框-->
    <inputaddproperty="component-name"message="Component name:(e.g. mycomponent) [Mandatory]"/>
    <input addproperty="component-resource-name" message="Component resource name: (e.g. MyComponent) [Mandatory]"/>
    <input addproperty="webapp-name" message="Webapp name: (e.g. mycomponent) [Mandatory]"/>
    <input addproperty="base-permission" message="Base permission: (e.g. MYCOMPONENT) [Mandatory]"/>
    <echo>Thefollowing hot-deploy component will be created:
          Name: ${component-name}
          Resource Name:${component-resource-name}
          Webapp Name: ${webapp-name}
          Base permission:${base-permission}
          Folder:${basedir}/hot-deploy/${component-name}
    </echo>
    <!--确认组件是否被创建-->
    <inputaddproperty="confirm-component-creation"message="Confirm: " defaultvalue="N" validargs="Y,N,y,n"/>
    <!--进行信息验证-->
    <failmessage="Component creationcancelled by the user.">
        <condition>
            <equals arg1="${confirm-component-creation}" arg2="N" casesensitive="false"/>
        </condition>
    </fail>
    <fail message="Component name is mandatory">
        <condition>
            <equals arg1="${component-name}" arg2="" casesensitive="false" trim="yes"/>
        </condition>
    </fail>
  <fail message="Resource name is mandatory">
        <condition>
            <equals arg1="${component-resource-name}" arg2="" casesensitive="false" trim="yes"/>
        </condition>
    </fail>
    <fail message="Webapp name is mandatory">
        <condition>
            <equals arg1="${webapp-name}" arg2="" casesensitive="false" trim="yes"/>
        </condition>
    </fail>
    <!--过滤器集,将文件中具体内容进行转化-->
   <filtersetid="replacePlaceholders">
        <filter token="component-name" value="${component-name}"/>
        <filter token="component-resource-name" value="${component-resource-name}"/>
        <filter token="base-permission" value="${base-permission!}"/>
        <filter token="webapp-name" value="${webapp-name}"/>
    </filterset>
    <!--创建文件-->
    <mkdirdir="${basedir}/hot-deploy/${component-name}"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/config"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/data"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/data/helpdata"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/dtd"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/documents"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/entitydef"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/lib"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/patches"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/patches/test"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/patches/qa"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/patches/production"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/script"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/servicedef"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/src"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/testdef"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/webapp"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/webapp/${webapp-name}"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/webapp/${webapp-name}/error"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/webapp/${webapp-name}/WEB-INF"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/webapp/${webapp-name}/WEB-INF/actions"/>
    <mkdir dir="${basedir}/hot-deploy/${component-name}/widget/"/>
    <1--拷贝文件模板-->
    <copyfile="${basedir}/framework/resources/templates/ofbiz-component.xml"tofile="${basedir}/hot-deploy/${component-name}/ofbiz-component.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/build.xml" tofile="${basedir}/hot-deploy/${component-name}/build.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/TypeData.xml" tofile="${basedir}/hot-deploy/${component-name}/data/${component-resource-name}TypeData.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/SecurityPermissionSeedData.xml"tofile="${basedir}/hot-deploy/${component-name}/data/${component-resource-name}SecurityPermissionSeedData.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/SecurityGroupDemoData.xml"tofile="${basedir}/hot-deploy/${component-name}/data/${component-resource-name}SecurityGroupDemoData.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/DemoData.xml" tofile="${basedir}/hot-deploy/${component-name}/data/${component-resource-name}DemoData.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/HELP.xml" tofile="${basedir}/hot-deploy/${component-name}/data/helpdata/HELP_${component-resource-name}.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/document.xml" tofile="${basedir}/hot-deploy/${component-name}/documents/${component-resource-name}.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/entitymodel.xml" tofile="${basedir}/hot-deploy/${component-name}/entitydef/entitymodel.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/services.xml" tofile="${basedir}/hot-deploy/${component-name}/servicedef/services.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/Tests.xml" tofile="${basedir}/hot-deploy/${component-name}/testdef/${component-resource-name}Tests.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/UiLabels.xml" tofile="${basedir}/hot-deploy/${component-name}/config/${component-resource-name}UiLabels.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/index.jsp" tofile="${basedir}/hot-deploy/${component-name}/webapp/${webapp-name}/index.jsp"encoding="iso-8859-1">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/error.jsp" tofile="${basedir}/hot-deploy/${component-name}/webapp/${webapp-name}/error/error.jsp"encoding="iso-8859-1">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/controller.xml" tofile="${basedir}/hot-deploy/${component-name}/webapp/${webapp-name}/WEB-INF/controller.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/web.xml" tofile="${basedir}/hot-deploy/${component-name}/webapp/${webapp-name}/WEB-INF/web.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/CommonScreens.xml" tofile="${basedir}/hot-deploy/${component-name}/widget/CommonScreens.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/Screens.xml" tofile="${basedir}/hot-deploy/${component-name}/widget/${component-resource-name}Screens.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/Menus.xml" tofile="${basedir}/hot-deploy/${component-name}/widget/${component-resource-name}Menus.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <copy file="${basedir}/framework/resources/templates/Forms.xml" tofile="${basedir}/hot-deploy/${component-name}/widget/${component-resource-name}Forms.xml"encoding="utf-8">
        <filterset refid="replacePlaceholders"/>
    </copy>
    <echo>Componentsuccessfully created in folder ${basedir}/hot-deploy/${component-name}.
          Restart OFBiz and then visitthe URL: http://localhost:8080/${webapp-name}
    </echo>
</target>

6.文件值替换(过滤器集)

     刚才上文输入的文本框值,不仅在创建文件是路径值替换,同时也替换里面具体的值,就拿ofbiz-component文件讲述

     文件位置

   /project/ofbiz/ofbiz-trunk/framework/resources/templates/ofbiz-component.xml

<?xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="@component-name@"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
    <!-- define resource loaders; most common is to use the component resource loader -->
    <resource-loader name="main" type="component"/>

    <!-- place the config directory on the classpath to access configuration files -->
    <classpath type="dir" location="config"/>
    <classpath type="dir" location="dtd"/>

    <!-- load single or multiple external libraries -->
    <classpath type="jar" location="build/lib/*"/>
    <classpath type="jar" location="lib/*"/>

    <!-- entity resources: model(s), eca(s), group, and data definitions -->
    <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
    <!-- <entity-resource type="eca" reader-name="main" loader="main" location="entitydef/eecas.xml"/> -->
    <entity-resource type="data" reader-name="seed" loader="main" location="data/@component-resource-name@TypeData.xml"/>
    <entity-resource type="data" reader-name="seed" loader="main" location="data/@component-resource-name@SecurityPermissionSeedData.xml"/>
    <entity-resource type="data" reader-name="demo" loader="main" location="data/@component-resource-name@SecurityGroupDemoData.xml"/>
    <entity-resource type="data" reader-name="demo" loader="main" location="data/@component-resource-name@DemoData.xml"/>

    <!-- service resources: model(s), eca(s) and group definitions -->
    <service-resource type="model" loader="main" location="servicedef/services.xml"/>
    <!--
    <service-resource type="eca" loader="main" location="servicedef/secas.xml"/>
    <service-resource type="group" loader="main" location="servicedef/groups.xml"/>
    -->

    <test-suite loader="main" location="testdef/@component-resource-name@Tests.xml"/>

    <!-- web applications; will be mounted when using the embedded container -->
    <webapp name="@webapp-name@"
        title="@component-resource-name@"
        server="default-server"
        location="webapp/@webapp-name@"
        base-permission="OFBTOOLS,@base-permission@"
        mount-point="/@webapp-name@"/>
</ofbiz-component>

      效果代码:

<?xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="component-name"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
    <!-- define resource loaders; most common is to use the component resource loader -->
    <resource-loader name="main" type="component"/>

    <!-- place the config directory on the classpath to access configuration files -->
    <classpath type="dir" location="config"/>
    <classpath type="dir" location="dtd"/>

    <!-- load single or multiple external libraries -->
    <classpath type="jar" location="build/lib/*"/>
    <classpath type="jar" location="lib/*"/>

    <!-- entity resources: model(s), eca(s), group, and data definitions -->
    <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
    <!-- <entity-resource type="eca" reader-name="main" loader="main" location="entitydef/eecas.xml"/> -->
    <entity-resource type="data" reader-name="seed" loader="main" location="data/resourec-nameTypeData.xml"/>
    <entity-resource type="data" reader-name="seed" loader="main" location="data/resourec-nameSecurityPermissionSeedData.xml"/>
    <entity-resource type="data" reader-name="demo" loader="main" location="data/resourec-nameSecurityGroupDemoData.xml"/>
    <entity-resource type="data" reader-name="demo" loader="main" location="data/resourec-nameDemoData.xml"/>

    <!-- service resources: model(s), eca(s) and group definitions -->
    <service-resource type="model" loader="main" location="servicedef/services.xml"/>
    <!--
    <service-resource type="eca" loader="main" location="servicedef/secas.xml"/>
    <service-resource type="group" loader="main" location="servicedef/groups.xml"/>
    -->

    <test-suite loader="main" location="testdef/resourec-nameTests.xml"/>

    <!-- web applications; will be mounted when using the embedded container -->
    <webapp name="webapp-name"
        title="resourec-name"
        server="default-server"
        location="webapp/webapp-name"
        base-permission="OFBTOOLS,${base-permission!}"
        mount-point="/webapp-name"/>
</ofbiz-component>

      就是这些值都被替换成了开始文本框的值,从而实现文件的拷贝,其它模板文件也在其同级目录下。

7.总结

     这就是创建组件的大概逻辑,详情研究代码,也可以自己模仿其定制自己想创建的模块结构,这样就不必手动创建,是个很方便的过程

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏IT探索

ld-linux.so.2

/lib/ld-linux.so.2以及它的64位版本/lib64/ld-linux-x86-64.so.2虽然看起来是共享库文件,但实际上他们可以独立运行。他...

371
来自专栏云加新鲜事儿

轻松入门腾讯云存储系列三:对象存储COS 使用入门三种方式

腾讯云目前支持三种不同的方式来登录和管理您的对象存储,请您根据自身场景灵活选择登录方式:控制台,CLI和API/SDKs。

2830
来自专栏SpringBoot 核心技术

第七章:SpringBoot整合JavaMail发送邮件

1474
来自专栏伪君子的梦呓

安装和配置 Eclipse

之前安装了 Java 并且配置好了 Java 的环境变量,现在来搞一下开发环境,下面就是下载安装和配置 Eclipse 的教程。

461
来自专栏别先生

Description Resource Path Location Type Project configuration is not up-to-date with pom.xml. Select

2626
来自专栏魏豪的专栏

Nagios 监控配置及实战

Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设备,打印机等。本文主要讲述Nagios ...

2370
来自专栏抠抠空间

爬虫之ssh证书警告错误

1640
来自专栏cmazxiaoma的架构师之路

FastDFS蛋疼的集群和负载均衡(十一)之清除Nginx文件缓存

2083
来自专栏hotqin888的专栏

MeritMS—利用beego实现数据库自动备份

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hotqin888/article/det...

611
来自专栏不止是前端

Vue:前后端数据联调

3419

扫描关注云+社区