Open Source Strategies
 
Main
About
Learn More
Services
Projects
Jobs
Contact

SourceForge.net Logo

A Tour of OFBiz

by Si Chen

This tutorial will walk you through OFBiz and one of its applications to help you understand the structure of OFBiz.

First, go into your OFBiz directory and take a look inside:

[sichen@localhost ofbiz_5010]$ ls -l
total 88
drwxrwxr-x   15 sichen   sichen       4096 May 20 07:54 applications
drwxrwxr-x    8 sichen   sichen       4096 May 20 07:59 base
-rw-rw-r--    1 sichen   sichen      10173 May 20 07:58 build.xml
drwxrwxr-x    4 sichen   sichen       4096 May 20 07:59 data
drwxrwxr-x   24 sichen   sichen       4096 May 20 07:58 framework
drwxrwxr-x    3 sichen   sichen       4096 May 20 07:52 hot-deploy
-rwxrwxr-x    1 sichen   sichen        309 May 20 07:58 ij.ofbiz
drwxrwxr-x    2 sichen   sichen       4096 May 20 08:08 logs
-rw-rw-r--    1 sichen   sichen      21167 May 20 08:07 ofbiz.jar
-rw-rw-r--    1 sichen   sichen       2869 May 20 07:58 rc.ofbiz
drwxrwxr-x    6 sichen   sichen       4096 May 20 07:55 specialized
-rw-rw-r--    1 sichen   sichen        265 May 20 07:58 startofbiz.bat
-rwxrw-r--    1 sichen   sichen        790 May 20 07:58 startofbiz.sh
-rwxrw-r--    1 sichen   sichen        325 May 20 07:58 stopofbiz.sh
drwxrwxr-x   12 sichen   sichen       4096 May 20 07:52 website
Things to note here:
  • OFBiz is built around a components-based architecture, which means each application is inside a component. This allows outside or custom applications to be added easily.
  • The applications/ directory holds the applications components, such as order manager and ecommerce store.
  • The framework/ directory holds the components for the OFBiz framework, such as the entity engine, and service engine.
  • specialized/ contains some other applications which are not part of the OFBiz core.
  • hot-deploy/ is another directory where components can be dropped in and automatically loaded.
  • base/ contains code for starting up and configuring ofbiz.
  • logs/ contains log files. On Unix/Linux, ofbiz runs as a background process, and all console output is in logs/console.log
  • website/ is the contents of ofbiz.org.

Now let's go inside framework/ and take a look:

[sichen@localhost ofbiz_5010]$ cd framework/
[sichen@localhost framework]$ ls -l
total 88
drwxrwxr-x    7 sichen   sichen       4096 May 20 08:00 appserver
drwxrwxr-x    8 sichen   sichen       4096 May 20 07:59 catalina
drwxrwxr-x   12 sichen   sichen       4096 May 20 08:00 common
-rw-rw-r--    1 sichen   sichen       2988 May 20 07:58 component-load.xml
drwxrwxr-x    6 sichen   sichen       4096 May 20 07:59 datafile
drwxrwxr-x   10 sichen   sichen       4096 May 20 07:59 entity
drwxrwxr-x    9 sichen   sichen       4096 May 20 07:59 entityext
drwxrwxr-x   12 sichen   sichen       4096 May 20 07:55 example
drwxrwxr-x    6 sichen   sichen       4096 May 20 08:00 guiapp
drwxrwxr-x    4 sichen   sichen       4096 May 20 07:56 images
drwxrwxr-x    6 sichen   sichen       4096 May 20 07:59 jetty
drwxrwxr-x    7 sichen   sichen       4096 May 20 07:59 jotm
drwxrwxr-x    6 sichen   sichen       4096 May 20 07:59 minerva
drwxrwxr-x    7 sichen   sichen       4096 May 20 08:00 minilang
drwxrwxr-x    9 sichen   sichen       4096 May 20 07:59 security
drwxrwxr-x   11 sichen   sichen       4096 May 20 07:59 service
drwxrwxr-x   12 sichen   sichen       4096 May 20 08:00 shark
drwxrwxr-x   10 sichen   sichen       4096 May 20 08:00 tests
drwxrwxr-x    9 sichen   sichen       4096 May 20 08:00 webapp
drwxrwxr-x    9 sichen   sichen       4096 May 20 08:00 webtools
drwxrwxr-x    6 sichen   sichen       4096 May 20 08:00 widget
drwxrwxr-x    9 sichen   sichen       4096 May 20 08:00 workflow
These are the components of the OFBiz framework, which is used to develop the OFBiz applications. component-load.xml controls which of the components in the current directory are loaded.

Now go back and take a look at the applications themselves:

[sichen@localhost framework]$ cd ..
[sichen@localhost ofbiz_5010]$ cd applications/
[sichen@localhost applications]$ ls -l
total 52
drwxrwxr-x   13 sichen   sichen       4096 May 20 08:00 accounting
-rw-rw-r--    1 sichen   sichen       2425 May 20 07:54 component-load.xml
drwxrwxr-x   15 sichen   sichen       4096 May 20 08:00 content
drwxrwxr-x   11 sichen   sichen       4096 May 20 08:00 ecommerce
drwxrwxr-x    5 sichen   sichen       4096 May 20 07:53 humanres
drwxrwxr-x   12 sichen   sichen       4096 May 20 08:00 manufacturing
drwxrwxr-x   12 sichen   sichen       4096 May 20 08:00 marketing
drwxrwxr-x   13 sichen   sichen       4096 May 20 08:00 order
drwxrwxr-x   12 sichen   sichen       4096 May 20 08:00 party
drwxrwxr-x   12 sichen   sichen       4096 May 20 08:00 pos
drwxrwxr-x   12 sichen   sichen       4096 May 20 08:00 product
drwxrwxr-x   10 sichen   sichen       4096 May 20 08:00 securityext
drwxrwxr-x   12 sichen   sichen       4096 May 20 08:00 workeffort
These are the OFBiz applications themselves. Each application is self-contained with its own data model definitions, business logic, and presentation (web or Swing) tier, although applications may reuse each others' business logic and thus depend on each other.

Now let's go inside an application and see what it looks like:

[sichen@localhost applications]$ cd product/
[sichen@localhost product]$ ls -l
total 52
drwxrwxr-x    4 sichen   sichen       4096 May 20 08:08 build
-rw-rw-r--    1 sichen   sichen       6413 May 20 07:53 build.xml
drwxrwxr-x    3 sichen   sichen       4096 May 20 07:53 config
drwxrwxr-x    3 sichen   sichen       4096 May 20 07:53 data
drwxrwxr-x    3 sichen   sichen       4096 May 20 07:53 entitydef
-rw-rw-r--    1 sichen   sichen       4202 May 20 07:53 ofbiz-component.xml
drwxrwxr-x    4 sichen   sichen       4096 May 20 07:53 script
drwxrwxr-x    3 sichen   sichen       4096 May 20 07:53 servicedef
drwxrwxr-x    4 sichen   sichen       4096 May 20 07:53 src
drwxrwxr-x    5 sichen   sichen       4096 May 20 07:53 webapp
drwxrwxr-x    5 sichen   sichen       4096 May 20 07:53 widget
Here is what you are seeing:
  • build/ is where the compiled Java code and any libraries for this application go.
  • build.xml tells ant how to build this application. It is like a Makefile.
  • config/ is for configuration data, such as internationalization (i18n) UI labels in various languages.
  • data/ is where the seed and demo data, in XML format, are located.
  • entitydef/ is where the data model definitions of this application are.
  • script/ is where scripts for business logic are. Scripts can be written in beanshell, OFBiz minilang, Jython, etc.
  • servicedef/ is where the services, which are small, granular pieces of business logic (similar to functions or methods), are defined.
  • src/ is where Java classes for implementing business logic are.
  • webapp/ is where the web interface, or front end, applications are. An OFBiz application can have more than one webapp.
  • ofbiz-component.xml defines this application by specifying where its data model, business logic, seed data, and web applications are located.

A look inside the entitydef/ and servicedef/ directories will show the XML files used to define the data model and business logic, respectively:

[si@localhost product]$ ls -l entitydef/
total 264
-rw-rw-r--    1 si       si           3094 May 27 08:00 eecas.xml
-rw-rw-r--    1 si       si          16862 May 27 08:00 entitygroup.xml
-rw-rw-r--    1 si       si          62923 May 27 08:00 entitymodel_shipment.xml
-rw-rw-r--    1 si       si         171582 May 27 08:00 entitymodel.xml
[si@localhost product]$ ls -l servicedef/
total 252
-rw-rw-r--    1 si       si           1836 May 27 08:00 groups_shipment.xml
-rw-rw-r--    1 si       si           5217 May 27 08:00 secas_shipment.xml
-rw-rw-r--    1 si       si           3897 May 27 08:00 secas.xml
-rw-rw-r--    1 si       si          42967 May 27 08:00 services_facility.xml
-rw-rw-r--    1 si       si          15516 May 27 08:00 services_feature.xml
-rw-rw-r--    1 si       si           9261 May 27 08:00 services_maint.xml
-rw-rw-r--    1 si       si           9411 May 27 08:00 services_picklist.xml
-rw-rw-r--    1 si       si          19216 May 27 08:00 services_pricepromo.xml
-rw-rw-r--    1 si       si           3374 May 27 08:00 services_shipment_ups.xml
-rw-rw-r--    1 si       si           5844 May 27 08:00 services_shipment_usps.xml
-rw-rw-r--    1 si       si          29717 May 27 08:00 services_shipment.xml
-rw-rw-r--    1 si       si          16205 May 27 08:00 services_store.xml
-rw-rw-r--    1 si       si           9817 May 27 08:00 services_view.xml
-rw-rw-r--    1 si       si          56540 May 27 08:00 services.xml

The webapp/ directory holds the web front end applications. A look inside shows that this application actually has two web applications, catalog and facility:

[si@localhost product]$ ls -l webapp/
total 8
drwxrwxr-x   18 si       si           4096 May 27 08:00 catalog
drwxrwxr-x   13 si       si           4096 May 27 08:00 facility
catalog/ is the OFBiz Catalog Manager, used to manage product information. facility/ is the OFBiz Facility Manager, used to manage warehouses and inventory.

In most dynamic web pages, there are some page elements, such as page headers, navigation bars, or shopping cart contents, that are repeated on many pages. When a visitor requests the page, the page will usually do some preprocessing, such as retrieving data from a database, and then present it to the user on a display page. In PHP, this is usually done by a SQL query first and then HTML code which presents the results of the query.

With OFBiz, pages are divided into smaller pieces which are re-combined to create the final product. Thus, many pages can share common elements such as page headers, sidebars, and navigation bars. This is called the "decorator pattern." There is a further separation of the activities of a page into "actions," such as getting data from a database, and "presentation," the display of that data to the visitor.

The "actions" in OFBiz are written in beanshell scripts, while the "presentation" is written in Freemarker template pages. Beanshell (.bsh) is a scripted version of Java, while Freemarker (.ftl) is a templating language that is used in OFBiz to create HTML or XSL:FO pages.

So here are the contents immediately inside a web application. The sub-directories hold the pieces of Freemarker pages:

[si@localhost product]$ ls -l webapp/catalog/
total 80
drwxrwxr-x    3 si       si           4096 May 27 08:00 catalog
drwxrwxr-x    3 si       si           4096 May 27 08:00 category
-rw-rw-r--    1 si       si           1866 May 27 08:00 ChooseTopCategory.ftl
drwxrwxr-x    3 si       si           4096 May 27 08:00 config
drwxrwxr-x    3 si       si           4096 May 27 08:00 error
-rw-rw-r--    1 si       si           1552 May 27 08:00 FastLoadCache.ftl
drwxrwxr-x    3 si       si           4096 May 27 08:00 feature
drwxrwxr-x    3 si       si           4096 May 27 08:00 find
drwxrwxr-x    3 si       si           4096 May 27 08:00 includes
-rw-rw-r--    1 si       si             44 May 27 08:00 index.jsp
drwxrwxr-x    3 si       si           4096 May 27 08:00 lookup
-rw-rw-r--    1 si       si           4575 May 27 08:00 main.ftl
drwxrwxr-x    3 si       si           4096 May 27 08:00 price
drwxrwxr-x    3 si       si           4096 May 27 08:00 product
drwxrwxr-x    3 si       si           4096 May 27 08:00 promo
drwxrwxr-x    3 si       si           4096 May 27 08:00 reviews
drwxrwxr-x    3 si       si           4096 May 27 08:00 store
drwxrwxr-x    3 si       si           4096 May 27 08:00 thesaurus
drwxrwxr-x    4 si       si           4096 May 27 12:21 WEB-INF
Most of the web application's page sections are put into different directories depending on their function. The includes/ directory holds many of the pieces of a web application. The WEB-INF directory is a "private" directory for files which should not be viewed directly by visitors. It holds files for controlling the flow logic and actions of this web application:
[si@localhost product]$ ls -l webapp/catalog/WEB-INF/
total 132
drwxrwxr-x   13 si       si           4096 May 27 08:00 actions
-rw-rw-r--    1 si       si         117202 May 27 08:00 controller.xml
-rw-rw-r--    1 si       si           4442 May 27 08:00 web.xml
  • controller.xml is a very important file that directs the flow of the web application. It maps URI requests from the visitor's browser to events, services, and pages.
  • web.xml contains supplemental information for the web application.
  • actions/ directory has beanshell scripts that are used to process and gather data for the pages.
The beanshell scripts in the WEB-INF/actions/ directory often mirror the Freemarker pages in the other directories. For example:
[si@localhost product]$ ls -l webapp/catalog/product/
total 240
-rw-rw-r--    1 si       si           6886 May 27 08:00 ApplyFeaturesFromCategory.ftl
-rw-rw-r--    1 si       si           2099 May 27 08:00 CreateVirtualWithVariantsForm.ftl
-rw-rw-r--    1 si       si          16552 May 27 08:00 EditProductAssoc.ftl
-rw-rw-r--    1 si       si           3813 May 27 08:00 EditProductAttributes.ftl
-rw-rw-r--    1 si       si           1407 May 27 08:00 EditProductContentContent.ftl
-rw-rw-r--    1 si       si          14132 May 27 08:00 EditProductContent.ftl
-rw-rw-r--    1 si       si           6126 May 27 08:00 EditProductDupForm.ftl
-rw-rw-r--    1 si       si           4519 May 27 08:00 EditProductFacilities.ftl
-rw-rw-r--    1 si       si           5273 May 27 08:00 EditProductFacilityLocations.ftl
-rw-rw-r--    1 si       si          13625 May 27 08:00 EditProductFeatures.ftl
-rw-rw-r--    1 si       si           5008 May 27 08:00 EditProductGlAccounts.ftl
-rw-rw-r--    1 si       si           4200 May 27 08:00 EditProductGoodIdentifications.ftl
-rw-rw-r--    1 si       si          13207 May 27 08:00 EditProductInventoryItems.ftl
-rw-rw-r--    1 si       si           6358 May 27 08:00 EditProductKeyword.ftl
-rw-rw-r--    1 si       si          23480 May 27 08:00 EditProductQuickAdmin.ftl
-rw-rw-r--    1 si       si          60917 May 27 08:00 ProductForms.xml
-rw-rw-r--    1 si       si           5721 May 27 08:00 ProductTabBar.ftl
-rw-rw-r--    1 si       si           6380 May 27 08:00 QuickAddVariants.ftl
[si@localhost product]$ ls -l webapp/catalog/WEB-INF/actions/product/
total 72
-rw-rw-r--    1 si       si           5862 May 27 08:00 ApplyFeaturesFromCategory.bsh
-rw-rw-r--    1 si       si           2489 May 27 08:00 ApplyFeaturesFromGroup.bsh
-rw-rw-r--    1 si       si           3548 May 27 08:00 EditProductAssoc.bsh
-rw-rw-r--    1 si       si           7490 May 27 08:00 EditProductContent.bsh
-rw-rw-r--    1 si       si           6920 May 27 08:00 EditProductContentContent.bsh
-rw-rw-r--    1 si       si           2574 May 27 08:00 EditProductFeatures.bsh
-rw-rw-r--    1 si       si          11386 May 27 12:27 EditProductInventoryItems.bsh
-rw-rw-r--    1 si       si          17166 May 27 08:00 EditProductQuickAdmin.bsh
-rw-rw-r--    1 si       si           1890 May 27 08:00 QuickAddVariants.bsh
There is not a one-to-one correspondence because the same beanshell script in actions/ can be reused for multiple pages, and also because some pages are pieced together from multiple Freemarker templates but require only one beanshell script.

Finally, there is one more component of an OFBiz application: the widgets/ directory:

[si@localhost product]$ ls -l widget/
total 8
drwxrwxr-x    3 si       si           4096 May 27 08:00 catalog
drwxrwxr-x    3 si       si           4096 May 27 08:00 facility
As you can see, this mirrors the contents of webapp/ from above. This is not an accident. The widgets/ directory holds "widgets" for rendering user interface screens. OFBiz allows user interface designs to be created as "generic screens" rather than just web pages, so they could be reused eventually for some other platform. The widgets/ directory's contents mirror those of the webapp/, so there are widgets for the catalog/ webapp and the facility/ webapp.

Now let's take a look at what's in a widgets directory:

[si@localhost product]$ ls -l widget/catalog/
total 176
-rwxrwxr-x    1 si       si          11824 May 27 08:00 CatalogScreens.xml
-rwxrwxr-x    1 si       si          19862 May 27 08:00 CategoryScreens.xml
-rw-rw-r--    1 si       si           9986 May 27 08:00 CommonScreens.xml
-rwxrwxr-x    1 si       si          11122 May 27 08:00 ConfigScreens.xml
-rw-rw-r--    1 si       si          10961 May 27 08:00 FeatureScreens.xml
-rwxrwxr-x    1 si       si           5937 May 27 08:00 FindScreens.xml
-rw-rw-r--    1 si       si           6695 May 27 08:00 LookupScreens.xml
-rwxrwxr-x    1 si       si           4440 May 27 08:00 PriceScreens.xml
-rw-rw-r--    1 si       si          39740 May 27 08:00 ProductScreens.xml
-rwxrwxr-x    1 si       si          14900 May 27 08:00 PromoScreens.xml
-rwxrwxr-x    1 si       si           3682 May 27 08:00 ReviewScreens.xml
-rwxrwxr-x    1 si       si          19802 May 27 08:00 StoreScreens.xml
-rwxrwxr-x    1 si       si           3588 May 27 08:00 ThesaurusScreens.xml
What you see are XML definitions for various screens here. The screens tell OFBiz how to create a screen: what pieces of common navigation elements, Freemarker page sections, and actions are required to create a particular page.

Now you've seen how an OFBiz application is put together. Future tutorials will show you how to develop one from scratch and customize an existing one.


© 2005-2007 Open Source Strategies, Inc. All rights reserved.