ofbiz helloworld

网上的例子都太老了,基本上对于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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements.  See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership.  The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License.  You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied.  See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. -->
  18. <ofbiz-component name="hello1"
  19. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  20. xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
  21. <resource-loader name="main" type="component"/>
  22. <webapp name="hello1"
  23. title="My First OFBiz Application"
  24. server="default-server"
  25. location="webapp/hello1"
  26. mount-point="/hello1"
  27. app-bar-display="false"/>
  28. </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文件或者从别的应用里边拷贝一个过来修改。

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPEweb-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
  3. <!--
  4. Licensedto the Apache Software Foundation (ASF) under one
  5. ormore contributor license agreements.  Seethe NOTICE file
  6. distributedwith this work for additional information
  7. regardingcopyright ownership.  The ASF licensesthis file
  8. to youunder the Apache License, Version 2.0 (the
  9. "License");you may not use this file except in compliance
  10. withthe License.  You may obtain a copy ofthe License at
  11. http://www.apache.org/licenses/LICENSE-2.0
  12. Unlessrequired by applicable law or agreed to in writing,
  13. softwaredistributed under the License is distributed on an
  14. "ASIS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. KIND,either express or implied.  See theLicense for the
  16. specificlanguage governing permissions and limitations
  17. underthe License.
  18. -->
  19. <web-app>
  20. <display-name>Hello1</display-name>
  21. <description>The First Hello WorldApplication</description>
  22. <context-param>
  23. <param-name>entityDelegatorName</param-name>
  24. <param-value>default</param-value>
  25. <description>The Name of theEntity Delegator to use, defined in entityengine.xml</description>
  26. </context-param>
  27. <context-param>
  28. <param-name>localDispatcherName</param-name>
  29. <param-value>hello1</param-value>
  30. <description>A unique name usedto identify/recognize the local dispatcher for the ServiceEngine</description>
  31. </context-param>
  32. <context-param>
  33. <param-name>serviceReaderUrls</param-name>
  34. <param-value>/WEB-INF/services.xml</param-value>
  35. <description>Configuration File(s)For The Service Dispatcher</description>
  36. </context-param>
  37. <filter>
  38. <filter-name>ContextFilter</filter-name>
  39. <display-name>ContextFilter</display-name>
  40. <filter-class>org.ofbiz.webapp.control.ContextFilter</filter-class>
  41. <init-param>
  42. <param-name>disableContextSecurity</param-name>
  43. <param-value>N</param-value>
  44. </init-param>
  45. <init-param>
  46. <param-name>allowedPaths</param-name>
  47. <param-value>/error:/control:/select:/index.html:/index.jsp:/default.html:/default.jsp:/images:/includes/maincss.css</param-value>
  48. </init-param>
  49. <init-param>
  50. <param-name>errorCode</param-name>
  51. <param-value>403</param-value>
  52. </init-param>
  53. <init-param>
  54. <param-name>redirectPath</param-name>
  55. <param-value>/control/main</param-value>
  56. </init-param>
  57. </filter>
  58. <filter-mapping>
  59. <filter-name>ContextFilter</filter-name>
  60. <url-pattern>/*</url-pattern>
  61. </filter-mapping>
  62. <listener><listener-class>org.ofbiz.webapp.control.ControlEventListener</listener-class></listener>
  63. <listener><listener-class>org.ofbiz.webapp.control.LoginEventListener</listener-class></listener>
  64. <servlet>
  65. <servlet-name>ControlServlet</servlet-name>
  66. <display-name>ControlServlet</display-name>
  67. <description>Main ControlServlet</description>
  68. <servlet-class>org.ofbiz.webapp.control.ControlServlet</servlet-class>
  69. <load-on-startup>1</load-on-startup>
  70. </servlet>
  71. <servlet-mapping>
  72. <servlet-name>ControlServlet</servlet-name>
  73. <url-pattern>/control/*</url-pattern>
  74. </servlet-mapping>
  75. <session-config>
  76. <session-timeout>60</session-timeout> <!-- in minutes-->
  77. </session-config>
  78. <welcome-file-list>
  79. <welcome-file>index.jsp</welcome-file>
  80. <welcome-file>index.html</welcome-file>
  81. <welcome-file>index.htm</welcome-file>
  82. </welcome-file-list>
  83. </web-app>

复制代码

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

  1. <?xmlversion="1.0" encoding="UTF-8" ?>
  2. <site-confxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/site-conf.xsd">
  4. <description>First Hello World SiteConfiguration File</description>
  5. <owner>Open For Business Project (c)2005 </owner>
  6. <errorpage>/error/error.jsp</errorpage>
  7. <handler name="java"type="request" class="org.ofbiz.webapp.event.JavaEventHandler"/>
  8. <handler name="soap"type="request"class="org.ofbiz.webapp.event.SOAPEventHandler"/>
  9. <handler name="service"type="request"class="org.ofbiz.webapp.event.ServiceEventHandler"/>
  10. <handler name="service-multi"type="request"class="org.ofbiz.webapp.event.ServiceMultiEventHandler"/>
  11. <handler name="simple"type="request"class="org.ofbiz.webapp.event.SimpleEventHandler"/>
  12. <handler name="ftl"type="view"class="org.ofbiz.webapp.ftl.FreeMarkerViewHandler"/>
  13. <handler name="jsp"type="view"class="org.ofbiz.webapp.view.JspViewHandler"/>
  14. <handler name="screen"type="view"class="org.ofbiz.widget.screen.ScreenWidgetViewHandler"/>
  15. <handler name="http"type="view" class="org.ofbiz.webapp.view.HttpViewHandler"/>
  16. <!-- Request Mappings -->
  17. <request-map uri="main">
  18. <response name="success"type="view" value="main"/>
  19. </request-map>
  20. <!-- end of request mappings -->
  21. <!-- View Mappings -->
  22. <view-map name="error"page="/error/error.jsp"/>
  23. <view-map name="main"type="ftl"page="component://hello1/webapp/hello1/main.ftl"/>
  24. <!-- end of view mappings -->
  25. </site-conf>

复制代码

6. 最后按照controller的配置,我们新建两个页面(error.jsp和 main.ftl)
在hello1/webapp/hello1目录下,新建一个error目录,并且在error目录下新建一个error.jsp文件

  1. <%@ pageimport="org.ofbiz.base.util.*" %>
  2. <html>
  3. <head>
  4. <title>Open For BusinessMessage</title>
  5. <metahttp-equiv="Content-Type" content="text/html;charset=iso-8859-1">
  6. </head>
  7. <% String errorMsg = (String)request.getAttribute("_ERROR_MESSAGE_"); %>
  8. <body bgcolor="#FFFFFF">
  9. <div>
  10. <table width="100%" border="1"height="200">
  11. <tr>
  12. <td>
  13. <table width="100%" border="0"height="200">
  14. <tr bgcolor="#CC6666">
  15. <td height="45">
  16. <divalign="center"><font face="Verdana, Arial, Helvetica,sans-serif" size="4"color="#FFFFFF"><b>:ERRORMESSAGE:</b></font></div>
  17. </td>
  18. </tr>
  19. <tr>
  20. <td>
  21. <divalign="left"><font face="Verdana, Arial, Helvetica,sans-serif"size="2"><%=UtilFormatOut.replaceString(errorMsg,"\n", "
  22. ")%></font></div>
  23. </td>
  24. </tr>
  25. </table>
  26. </td>
  27. </tr>
  28. </table>
  29. </div>
  30. <divalign="center"></div>
  31. </body>
  32. </html>

复制代码

在hello1/webapp/hello1目录下新建一个main.ftl文件

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.0 Transitional//EN">
  2. <HTML>
  3. <title>Hello World</title>
  4. <HEAD>
  5. <META content="text/html;charset=utf-8" http-equiv=Content-Type></HEAD>
  6. <BODY>
  7. <h1>HELLO</h1>
  8. Hello world!
  9. </BODY></HTML>

复制代码

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

时间: 2024-07-31 15:24:29

ofbiz helloworld的相关文章

OFBiz进阶之HelloWorld(一)创建热部署模块

创建热部署模块 参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guide 1 在目录hot-deploy下创建目录practice(即为要创建的模块名称) 2 在目录hot-deploy/practice下创建文件ofbiz-component.xml 1 <?xml version="1.0" encoding="UTF-8

OFBiz进阶之HelloWorld(三)使用 Form Widget

1. Now add one more menu item to by name "PersonForm" to your PracticeMenus.xml file. <menu-item name="PersonForm" title="PersonForm"> <link target="PersonForm" /> </menu-item> 2. Create one file i

OFBiz进阶之HelloWorld(五)创建新实体

1 Creating Custom Entity 新实体的创建你可以再参考 example 组件,为此你可以看下 example 组件的 entitymodel.xml 文件.你可以按下列步骤创建新的实体: a. 在 hot-deploy/practice/  下创建一个 entitydef 的子目录. b. 创建一个 entitymodel.xml 文件.这个文件包括你想定义的实体定义. c. 要装载定义,你需要在 ofbiz-component.xml 文件中定义一个条目,如下: <enti

OFBiz进阶之HelloWorld(二)创建热部署模块

参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guide Going ahead, you will create some advanced GUI patterns, interact with existing database tables and will learn how to secure your web application. 1

Ofbiz:Hello Ofbiz!

Ofbiz是Apache的顶级项目,大概就是一个做金融相关的网站的框架吧,其文档也还没仔细看,万事开头难,先来个Hello World!从最基础的HelloWorld开始吧.下载完成后,解压就行了,前提是JAVA_HOME这些东西应该设置好的. 1.构建ofbiz.jar,解压后,这东西是不存在的,害得我找了半天,双击ant.bat就会构建出这个jar包,中间一大串警告... 2.按照教程一步一步来,当然你也可以下载我已经建好的,放到hot-deploy就行了.. 3.启动ofbiz,可以写个b

Java小白入门学习笔记demo1输出helloworld

public class Hello{//公共   类     类名  public static void main(String[] args){ //     公共   静态  无返回值 主方法(字符串[] 参数)   System.out.println("helloworld"); //   系统.输出.打印换行(输出内容); // 输出语句,首字母必须大写,println为输出内容后自动换行,print输出内容不换行 }}

SpringBoot学习helloworld

这几天开始学习springBoot记录一下(Hello World) pom.xml 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.o

Egret 学习之 从HelloWorld项目开始 (二)

1,创建新项目HelloWorld ,可以在界面上点击文件->新建,也可以在命令行使用create: 2,src 目录,存放我们的代码.我们编写的代码都放在src目录下面. bin-debug 目录,项目编译和运行的debug目录,一般我们不要修改该目录下的内容. libs 目录,这里面存放我们的库文件,包括 Egret 核心库和其他扩展库.当然以后添加了第三方库的话也会放在这里. resource 目录,这里放置我们的资源文件,这里面有一个default.res.json 配置文件,用来配置资

HelloWorld 模块

helloworld.c 代码 1 #include <linux/init.h> 2 #include <linux/module.h> 3 4 MODULE_LICENSE("Dual BSD/GPL"); 5 6 static int hello_init(void) 7 { 8 printk(KERN_ALERT "Hello world\n"); 9 return 0; 10 } 11 12 static void hello_ex