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 条评论
登录 后参与评论

相关文章

来自专栏云计算教程系列

如何使用Nginx在Ubuntu 16.04上使用SSL保护Concourse CI

Concourse CI是一个现代且可扩展的持续集成系统,旨在通过可组合的声明性语法自动化测试管道。基于早期CI系统的成功,Concourse旨在简化管道管理并...

240
来自专栏好好学java的技术栈

手把手从零开始带你学git和GitHub

版本: 想想你平时用的软件,在软件升级之后,你用的就是新版本的软件。你应该见过这样的版本号:v2.0 或者 1511(表示发布时为15年11月),如下图:

482
来自专栏梦魇小栈

NPM 学习笔记整理

npm 之于 Node ,就像 pip 之于 Python , gem 之于 Ruby , composer 之于 PHP 。

440
来自专栏沈唁志

怎么快速集成QQ微博等第三方授权登录功能?

日常项目中经常会用到QQ授权登录或者微信授权登录,方便了用户,否则需要手机验证码等等的操作,授权登录只需要一键操作

881
来自专栏PHP技术大全

Grafana+prometheus+php 自动创建监控图

在grafana+ prometheus+php 监控系统实践文章当中已经实现了我们的第一个监控图表,现在我们有了一个新需求,需要对多个节点实现不同的监控,以及...

1463
来自专栏我的博客

vsftp +mysql 配置详细过程

本文章由网友:苶然(QQ网名)供稿,在此特别感谢他 需要安装包 db4-* vsftpd- mysql-server mysql-devel pam...

3095
来自专栏我和PYTHON有个约会

python-应用层-网络编程-FTP

前面描述的基于TCP/UDP协议的网络程序开发,主要是针对传输层协议的底层代码实现 在实际操作过程中,更多的情况是直接操作应用层的数据协议的网络程序开发,如文...

953
来自专栏屈政斌的专栏

【腾讯云的1001种玩法】centos 7 部署 dotnetcore + Angular2 实践

本文主要讲述了使用腾讯云主机,在centos 7 部署 dotnetcore + Angular2 的实践过程,该项目目前只是用于学习 dotnetcore ...

2.4K1
来自专栏编程坑太多

『高级篇』docker之kubernetes搭建集群添加认证授权(上)(38)

kubernetes的安装有几种方式,不管是kube-admin还是社区贡献的部署方案都离不开这几种方式:

834
来自专栏从零开始学自动化测试

python接口自动化17-响应时间与超时(timeout)

前言 requests发请求时,接口的响应时间,也是我们需要关注的一个点,如果响应时间太长,也是不合理的。 如果服务端没及时响应,也不能一直等着,可以设置一个t...

3936

扫码关注云+社区