OFBiz Tutorial – Custom Components in OFBiz

Jacopo CappellatoPublished: Updated:

Edit – First time this post was published in 2009 working with OFBiz trunk, updated it to work with OFBiz latest Release 16.11.

This is the first of a series of posts that will introduce hands-on Apache OFBiz® development: each post will focus on a simple exercise that will unveil some of the powerful features of OFBiz.

In this post we will simply setup our sandbox environment: a custom component/application named “hotwax” that is deployed in OFBiz and will contain our exercises.

OFBiz components

OFBiz Components

At its bare minimum, an OFBiz component is a folder, containing a special xml file, named “ofbiz-component.xml”, that describes the resources loaded and required by the component.
OFBiz itself is made up of components:

  • framework components: lower level components that provide the technical layer and tools to the application components; the features provided by these components are typically the ones provided by any other development framework (data layer, business logic layer, transaction handling, data source pools, etc…)
  • application components: they are generic ERP applications that can be used as they are or extended/customized (product, order, party, manufacturing, accounting etc…); application components have access to the services and tools provided by the framework components and to the services published by other application components
  • special purpose components: similar to the application components, the are special purpose applications like ecommerce, Google Base integration, eBay integration etc…
  • hot-deploy components: this folder is empty and it is where you can place your custom components; custom components have access to, and can extend/override, the resources published by all the other components

Prerequisites

  • Java SDK 8 is properly installed and the JAVA_HOME environment variable is correctly set; you can download Java from http://www.oracle.com/technetwork/java/javase/downloads/index.html
  • Apache Subversion® client is installed in your system (needed to checkout the latest OFBiz sources); you can freely download an svn client from http://subversion.apache.org/packages.html.

Setting up the sandbox

These are the simple steps to download and build OFBiz and your custom component:

  1. Download the OFBiz Framework source files from the official OFBiz SVN Respository (this step can take some time and requires access to the Internet): “svn co http://svn.apache.org/repos/asf/ofbiz/branches/release16.11 ofbiz.16.11”
  2. go to the newly created folder: “cd ofbiz-framework”
  3. run the Gradle task to create a standard OFBiz component/plugin: “./gradlew createPlugin -PpluginId=hotwax”
  4. build OFBiz and load the demo data: “./gradlew loadDefault”
  5. run OFBiz: “./gradlew ofbiz –start”

In short, here are the commands you have to type in a shell:

Now OFBiz and your custom applications are up and running; just point your browser to: http://localhost:8080/hotwax
Login into the custom “hwm” application with username “admin” and password “ofbiz”.

More about the “createPlugin” script

Even if you can of course manually create a plugin, running the gradle task “createPlugin” is the preferred way of starting with a new custom component because it is quick and generates a component layout that follows all the OFBiz best practices, enabling you to use and extend the existing OFBiz goodies:

  • entities (the data model)
  • services (business logic)
  • widgets (user interface elements like screens, forms, menus)
  • security (authentication and authorization)
  • localization
  • tools
  • etc…

The main advantage of using this development strategy is that all your custom code will be separated from the official OFBiz code, drastically simplifying the task of keeping your custom application updated with the new OFBiz versions. You will still be able to extend/override/customize specific OFBiz entities, services, screens and of course add new ones, just writing code into your custom component.

For the most curious of you, here are some details about the component/plugin you have just setup:

  • component name: this is the name of the component (and also of the folder that will contain it, created in the specialpurpose folder); following OFBiz’s naming conventions, it should be a single word all lowercased (e.g. hotwax)
  • component resource name: it will be used as a prefix for resources; you can just use the component name, possibly using an upper case character for the first character in the words (e.g. Hotwax)
  • webapp name: this is the name and uri of the application in which the ui for the new component will be implemented; following OFBiz’s naming conventions, it should be a single word all lowercased (e.g. hotwax)
  • base permission: this is the prefix for base security permissions; following OFBiz’s naming conventions, it should be a single word all uppercased (e.g. HOTWAX)

The script will setup a new component in the “specialpurpose” folder, with the following layout:

The layout of the custom component “hotwax”

You may already recognize how the automated script for creating a new plugin has setup this OFBiz Component for you.

Exploring the component layout

Now we have everything we need to start to practice with the development based on the OFBiz framework. In the upcoming posts we will use this component to perform some exercises that will help us to better understand how OFBiz works and how to use it to build powerful ERP applications.

Apache, Apache OFBiz, Apache Subversion are trademarks of the Apache Software Foundation.

"Unify.> Visit HotWax.co”/>

Jacopo Cappellato About Jacopo Cappellato
Jacopo Cappellato is VP of Technology at HotWax Media and has been involved with the OFBiz project since 2003. He is an OFBiz Project Committer and a member of both the OFBiz Project Management Committee and the Apache Software Foundation.

Comments 20

  1. Pingback: OFBiz Tutorial - Building A Simple Product List Screen | Apache OfBiz Blog - HotWax Media

  2. Avatar for Jacopo Cappellato
    1. Avatar for Jacopo Cappellato
  3. Avatar for Jacopo Cappellato

    After completing the tutorial I tried a “ant build” and an “ant run-install”, but it doesn’t like the build.xml file from the create-component command.

    /opt/ofbiz-release9.04/build.xml:157: The following error occurred while executing this line:
    Target “classes” does not exist in the project “OFBiz – Hwm Component”. It is used from target “jar”.

    Now I noticed that there are no classes in hwm/build/classes, should I disable or delete the build.xml file to get around this error?

    Thanks, and thanks for the other response.

    1. Avatar for Jacopo Cappellato

      Hi Patrick,

      thank you for your interest about our blog.
      I have noticed that you are running the tutorial using the OFBiz release 9.04 version; my suggestion is to use a newer version (the trunk or a nightly build that you can easily download from here ).
      BTW, today I have tested the tutorial using the release 9.04 and it worked. What JDK version are you using? I guess it is a 1.4 version and the “classes” target of the generated “hwm” component requires 1.5 or above.
      Let us know if this helps you.

      Jacopo

  4. Pingback: OFBiz Tutorial - Enhancing the Product list screen | Apache OfBiz Blog - HotWax Media

  5. Avatar for Jacopo Cappellato
  6. Avatar for Jacopo Cappellato

    Thanks for the tutorial. It worked perfectly for me. I’m looking forward seeing what kind of applications I can create with OFBiz.

    1. Avatar for Jacopo Cappellato
  7. Avatar for Jacopo Cappellato
  8. Avatar for Jacopo Cappellato
  9. Avatar for Jacopo Cappellato

    Thanks for the info on the sandbox. I have been having trouble getting my sandbox to work.
    Great Tutorial. Thank You.

  10. Avatar for Jacopo Cappellato

    Hotwax,

    Thanks for the tutorial. Helped me get around a few problems that I have been struggling with for the past couple of hours.

    Cheers
    Rich

  11. Avatar for Jacopo Cappellato

    hi, thanks for the tutorial, but unfortunately i can’t make it works 🙁
    i’ve got this error:

    org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen [component://test/widget/CommonScreens.xml#main-decorator]: java.lang.IllegalArgumentException: Could not find resource bundle [TestUiLabels] in the locale [en_US] (Could not find resource bundle [TestUiLabels] in the locale [en_US])

    do you know what went wrong?

    any help would be appreciated 🙂
    thanks,
    arini

    1. Avatar for Jacopo Cappellato

      Hi Arini,

      sorry for the awfully late reply to your question. You are getting that error because the renderer can’t locate the file Tes1UiLabels.xml; please check if the file is in the config folder.

      Kind regards,

      Jacopo

  12. Avatar for Jacopo Cappellato

    Hi,
    I’m not getting the following message.
    org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen [component://test/widget/CommonScreens.xml#main-decorator]: java.lang.IllegalArgumentException: Could not find resource bundle [TestUiLabels] in the locale [en_US] (Could not find resource bundle [TestUiLabels] in the locale [en_US])
    Can you help me out here.

    Rgds,
    Amit

    1. Avatar for Jacopo Cappellato
  13. Avatar for Jacopo Cappellato
  14. Avatar for Jacopo Cappellato

    Plugins are standard OFBiz components that reside in the specialpurpose directory. Plugins can be
    added manually or fetched from a maven repository. The standard tasks for create new plugin is giving below.
    To Create a new plugin. The following project parameters are passed:
    – pluginId: mandatory
    – pluginResourceName: optional, default is the Capitalized value of pluginId
    – webappName: optional, default is the value of pluginId
    – basePermission: optional, default is the UPPERCASE value of pluginId

    Enter following command below to create component/plugin,

    ./gradlew createPlugin -PpluginId=myplugin
    or
    ./gradlew createPlugin -PpluginId=myplugin -PpluginResourceName=MyPlugin -PwebappName=mypluginweb -PbasePermission=MYSECURITY`

    The above commands achieve the following:
    – create a new plugin in /specialpurpose/myplugin
    – add the plugin to /specialpurpose/component-load.xml

    Once the component is created, you should load its data (required to grant access rights to the “admin” user);
    ./gradlew “ofbiz –shutdown”
    ./gradlew loadDefault
    ./gradlew
    ./gradlew ofbiz

    To Know more:
    https://ikziko.blogspot.com/2017/03/create-ofbiz-component-plugin_15.html

  15. Avatar for Jacopo Cappellato

Leave a Reply

Your email address will not be published. Required fields are marked *