`
kefumao
  • 浏览: 4482 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Ofbiz12.04 进阶之三 第一个Helloword的应用

阅读更多
网上的例子都太老了,基本上对于ofbiz12.04都跑不起来,所以今天自己做了一个,下面来分享一下
参考:http://www.opensourcestrategies.com/ofbiz/hello_world1.php

1. 创建一个应用叫hello1,在ofbiz里,一个应用可以创建在 framework/, application/, specialized/, 或者 hot-deploy/ 目录下,为了方便起见我们建立在hot-deploy/ 目录下,因为这个目录下的应用时热部署,直接改动不需要重新启动服务器,省时,方便调试。
在hot-deploy/目录下创建一个文件夹名为hello1

2.在ofbiz里边,每个应用组件里必须要包含一个 ofbiz-component.xml 文件,这个文件告诉ofbiz在你的应用里所包含的的table,service,业务逻辑,表现层。。。
在hello1目录下创建一个文件名为ofbiz-component.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<ofbiz-component name="hello1"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
<resource-loader name="main" type="component"/>
<webapp name="hello1"
   title="My First OFBiz Application"
   server="default-server"
   location="webapp/hello1"
   mount-point="/hello1"
   app-bar-display="false"/>   
</ofbiz-component>

-ofbiz-component name="hello1"----这个组件名为hello1
-<resource-loader name="main" type="component"/>---用 “main” 这个resource-loader,这个基本上是默认的
- webapp name="hello1"  ----- 这个组件有一个应用叫hello1
- server="default-server" -----这个组件所用的servcer是default-server
-location="webapp/hello1" ---- 这个应用的所有资源都在webapp/hello1/这个目录下
- mount-point="/hello1"----- 这个应用的URI为hello1
因为我们不想他出现在app-bar里,所以这里设置为false,反则设置为true

3. 下面我们开始为hello1这个组件建立一个名为hello1的应用。
在hello1这个目录下建立一个文件夹名为webapp,之后再webapp文件夹里边再建立一个文件夹名为hello1。


4. 对于每一个web application,都应该有一个web描述文件,即web.xml
那么我们在webapp目录下建一个WEB-INF目录,在WEB-INF目录下边新建一个web.xml文件或者从别的应用里边拷贝一个过来修改。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPEweb-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<!--
Licensedto the Apache Software Foundation (ASF) under one
ormore contributor license agreements.  Seethe NOTICE file
distributedwith this work for additional information
regardingcopyright ownership.  The ASF licensesthis file
to youunder the Apache License, Version 2.0 (the
"License");you may not use this file except in compliance
withthe License.  You may obtain a copy ofthe License at

http://www.apache.org/licenses/LICENSE-2.0

Unlessrequired by applicable law or agreed to in writing,
softwaredistributed under the License is distributed on an
"ASIS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND,either express or implied.  See theLicense for the
specificlanguage governing permissions and limitations
underthe License.
-->

<web-app>
   <display-name>Hello1</display-name>
   <description>The First Hello WorldApplication</description>

  <context-param>
      <param-name>entityDelegatorName</param-name>
      <param-value>default</param-value>
       <description>The Name of theEntity Delegator to use, defined in entityengine.xml</description>
   </context-param>
   <context-param>
      <param-name>localDispatcherName</param-name>
      <param-value>hello1</param-value>
       <description>A unique name usedto identify/recognize the local dispatcher for the ServiceEngine</description>
   </context-param>
<context-param>
      <param-name>serviceReaderUrls</param-name>
      <param-value>/WEB-INF/services.xml</param-value>
       <description>Configuration File(s)For The Service Dispatcher</description>
   </context-param>
   <filter>
      <filter-name>ContextFilter</filter-name>
      <display-name>ContextFilter</display-name>
      <filter-class>org.ofbiz.webapp.control.ContextFilter</filter-class>
       <init-param>
          <param-name>disableContextSecurity</param-name>
          <param-value>N</param-value>
       </init-param>
       <init-param>
          <param-name>allowedPaths</param-name>
          <param-value>/error:/control:/select:/index.html:/index.jsp:/default.html:/default.jsp:/images:/includes/maincss.css</param-value>
       </init-param>
       <init-param>
          <param-name>errorCode</param-name>
           <param-value>403</param-value>
       </init-param>
       <init-param>
          <param-name>redirectPath</param-name>
          <param-value>/control/main</param-value>
       </init-param>
   </filter>
   <filter-mapping>
       <filter-name>ContextFilter</filter-name>
          <url-pattern>/*</url-pattern>
   </filter-mapping>

  <listener><listener-class>org.ofbiz.webapp.control.ControlEventListener</listener-class></listener>
  <listener><listener-class>org.ofbiz.webapp.control.LoginEventListener</listener-class></listener>

   <servlet>
      <servlet-name>ControlServlet</servlet-name>
      <display-name>ControlServlet</display-name>
       <description>Main ControlServlet</description>
      <servlet-class>org.ofbiz.webapp.control.ControlServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
      <servlet-name>ControlServlet</servlet-name>
      <url-pattern>/control/*</url-pattern>
   </servlet-mapping>

   <session-config>
      <session-timeout>60</session-timeout> <!-- in minutes-->
   </session-config>

   <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>index.html</welcome-file>
      <welcome-file>index.htm</welcome-file>
  </welcome-file-list>
</web-app>

5.ofbiz是基于MVC的框架,那么对于它的每一个应用来说我们一、都要配置一个controller.xml文件
在WEB-INF目录下边新建一个controller.xml文件或者从别的应用里边拷贝一个过来修改
<?xmlversion="1.0" encoding="UTF-8" ?>

<site-confxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/site-conf.xsd">
   <description>First Hello World SiteConfiguration File</description>
   <owner>Open For Business Project (c)2005 </owner>
  <errorpage>/error/error.jsp</errorpage>

   <handler name="java"type="request" class="org.ofbiz.webapp.event.JavaEventHandler"/>
   <handler name="soap"type="request"class="org.ofbiz.webapp.event.SOAPEventHandler"/>
   <handler name="service"type="request"class="org.ofbiz.webapp.event.ServiceEventHandler"/>
   <handler name="service-multi"type="request"class="org.ofbiz.webapp.event.ServiceMultiEventHandler"/>
   <handler name="simple"type="request"class="org.ofbiz.webapp.event.SimpleEventHandler"/>

   <handler name="ftl"type="view"class="org.ofbiz.webapp.ftl.FreeMarkerViewHandler"/>
   <handler name="jsp"type="view"class="org.ofbiz.webapp.view.JspViewHandler"/>
   <handler name="screen"type="view"class="org.ofbiz.widget.screen.ScreenWidgetViewHandler"/>

   <handler name="http"type="view" class="org.ofbiz.webapp.view.HttpViewHandler"/>



   <!-- Request Mappings -->
   <request-map uri="main">
       <response name="success"type="view" value="main"/>
   </request-map>

   <!-- end of request mappings -->

   <!-- View Mappings -->
   <view-map name="error"page="/error/error.jsp"/>
   <view-map name="main"type="ftl"page="component://hello1/webapp/hello1/main.ftl"/>
   <!-- end of view mappings -->
</site-conf>

6. 最后按照controller的配置,我们新建两个页面(error.jsp和 main.ftl)
在hello1/webapp/hello1目录下,新建一个error目录,并且在error目录下新建一个error.jsp文件
<%@ pageimport="org.ofbiz.base.util.*" %>
<html>
<head>
<title>Open For BusinessMessage</title>
<metahttp-equiv="Content-Type" content="text/html;charset=iso-8859-1">
</head>

<% String errorMsg = (String)request.getAttribute("_ERROR_MESSAGE_"); %>

<body bgcolor="#FFFFFF">
<div>
<br/>
<table width="100%" border="1"height="200">
  <tr>
    <td>
      <table width="100%" border="0"height="200">
        <tr bgcolor="#CC6666">
          <td height="45">
             <divalign="center"><font face="Verdana, Arial, Helvetica,sans-serif" size="4"color="#FFFFFF"><b>:ERRORMESSAGE:</b></font></div>
          </td>
        </tr>
        <tr>
          <td>
             <divalign="left"><font face="Verdana, Arial, Helvetica,sans-serif"size="2"><%=UtilFormatOut.replaceString(errorMsg,"\n", "<br/>")%></font></div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</div>
<divalign="center"></div>
</body>
</html>

在hello1/webapp/hello1目录下新建一个main.ftl文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.0 Transitional//EN">
<HTML>
<title>Hello World</title>
<HEAD>
<META content="text/html;charset=utf-8" http-equiv=Content-Type></HEAD>
<BODY>
<h1>HELLO</h1>
Hello world!

</BODY></HTML>


基本上一个新的组件就已经完成了,因为我们的组件是建立在hot-deploy目录下,所以运行ofbiz,这个组件直接就被加载了。如果想要把这个组件放到applications目录下,需要修改applications目录下的component-load.xml文件
在<component-loader> </component-loader>里边添加一行<load-componentcomponent-location="hello1"/>,这样当我们从新启动ofbiz的时候这个组件就会被ofbiz所加载。
0
7
分享到:
评论

相关推荐

    ofbiz12.04表结构(msyql)

    逆向ofbiz 12.04的表结构,总计 863张表,带外键

    OFBIZ快速入门OFBIZ快速入门

    【OFBIZ快速入门】 OFBiz,全称Open For Business Project,是一个开源的企业级应用框架,专注于电子商务和业务流程管理。...快速入门只是第一步,持续的学习和实践将帮助你更好地掌握OFBiz的精髓。

    OFBIZ集成Activiti流程

    OFBiz集成Spring和Activiti,详细设计说明书。ofbiz版本12.04

    ofbiz api开发文档

    在信息技术领域,OFBiz(Open For Business Project)是一个开源的企业级应用框架,主要用于构建复杂的电子商务系统。OFBiz 提供了一整套全面的业务组件,涵盖了从供应链管理到客户关系管理的诸多方面。本文将深入...

    ofbiz开发入门总结

    Ofbiz,全称Open For Business Project,是一个开源的企业级应用框架,主要用于构建复杂的电子商务和企业管理系统。它基于Java技术,提供了丰富的组件模型和灵活的业务流程,使得开发者能够快速搭建并扩展业务系统。...

    ofbiz开发手册

    本文档将作为一个 OFBiz 的入门教材,主要介绍 OFBiz 的环境搭建、安装以及用一个简单的应用作为例子介绍了 OFBiz 应用开发的流程。 OFBiz 环境搭建 OFBiz 环境搭建是指在开发和测试 OFBiz 应用程序所需的基础环境...

    用OFBiz创建一个完整的应用(翻译hello3)

    创建OFBiz应用的第一步是设置开发环境。你需要下载OFBiz的源代码,并配置相应的开发工具,如Eclipse或IntelliJ IDEA。确保你的环境中已经安装了Java JDK,因为OFBiz是用Java语言编写的。同时,你也需要熟悉Ant或...

    OFBIZ浏览组件第三部分

    OFBIZ浏览组件第三部分OFBIZ浏览组件第三部分OFBIZ浏览组件第三部分OFBIZ浏览组件第三部分OFBIZ浏览组件第三部分OFBIZ浏览组件第三部分OFBIZ浏览组件第三部分

    Ofbiz 数据库全模型

    Ofbiz,全称为The Open For Business Project,是一个开源的企业应用框架,主要由Apache软件基金会维护。这个项目旨在提供一套全面的、可扩展的企业级应用程序解决方案,涵盖了电子商务、供应链管理、客户关系管理等...

    ofbiz 英文pdf

    - **第一章:OFBiz入门**(Chapter1:Getting Started with OFBiz) - **获取OFBiz代码**:通过SVN下载OFBiz项目。 - **下载并安装SVN**:详细介绍如何安装Subversion客户端。 - **使用TortoiseSVN**:推荐使用...

    ofbiz10.04表结构

    标题中的"ofbiz10.04表结构"指的是OFBiz 10.04版本的数据模型设计,这是企业级开源应用框架OFBiz的一个重要组成部分。OFBiz全称为Open For Business Project,它是一个用于构建企业应用程序的全面业务解决方案,涵盖...

    ofbiz开发入门之CmsBackEnd实现的CRUD

    在IT行业中,Apache OFBiz(Open For Business Project)是一个企业级的开源应用框架,主要用于构建电子商务、供应链管理和CRM等业务应用程序。本篇文章将探讨的是OFBiz的开发入门,特别是关于CmsBackEnd如何实现...

    ofbiz入门实例(jiasudu制作)

    通过这个"Ofbiz入门实例",初学者将能够逐步熟悉Ofbiz的各个层面,从基础到进阶,掌握一个完整的Ofbiz应用开发流程。同时,这个教程也适合已经有一定Java基础的开发者,他们可以通过实践进一步提升对企业级应用开发...

    ofbiz中文技术文档

    Ofbiz(Open for Business Project)是一个开源的企业级应用框架,主要用于构建电子商务、供应链管理、客户关系管理等业务系统。它由Apache软件基金会维护,提供了一个灵活且可扩展的平台,让开发者可以快速构建定制...

    ofbiz一个完整例子

    OFBiz,全称为Open For Business Project,是一个开源的企业应用框架,用于构建企业级的电子商务、供应链管理和CRM等复杂业务系统。本示例将带你逐步了解如何在OFBiz中创建一个完整的应用实例,从实体创建到服务定义...

    ofbiz开发者入门教程

    在本教程中,我们将深入探讨如何入门Apache Ofbiz的开发,这是一个开源的企业级应用框架,专为电子商务、供应链管理和企业资源规划等业务流程设计。Ofbiz提供了强大的组件化架构,使得开发者可以方便地构建和扩展...

    Apache.OFBiz.Development

    1. OFBiz介绍与安装:OFBiz是一个开源的企业自动化软件套件,它提供了构建企业应用程序所需的各种功能,比如电子商务、订单处理等。文件中提到了2008年的版本,这意味着可能有较新的版本替代。安装OFBiz涉及到获取源...

Global site tag (gtag.js) - Google Analytics