34,79 €
Apache Open For Business (OFBiz) is an enterprise resource planning (ERP) system that provides a common data model and an extensive set of business processes. But without proper guidance on developing performance-critical applications, it is easy to make the wrong design and technology decisions. The power and promise of Apache OFBiz is comprehensively revealed in a collection of self-contained, quick, practical recipes in this Cookbook.
This book covers a range of topics from initial system setup to web application and HTML page creation, Java development, and data maintenance tasks. Focusing on a series of the most commonly performed OFBiz tasks, it provides clear, cogent, and easy-to-follow instructions designed to make the most of your OFBiz experience.
Let this book be your guide to enhancing your OFBiz productivity by saving you valuable time. Written specifically to give clear and straightforward answers to the most commonly asked OFBiz questions, this compendium of OFBiz recipes will show you everything you need to know to get things done in OFBiz.
Whether you are new to OFBiz or an old pro, you are sure to find many useful hints and handy tips here. Topics range from getting started to configuration and system setup, security and database management through the final stages of developing and testing new OFBiz applications.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 328
Veröffentlichungsjahr: 2010
Copyright © 2010 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: September 2010
Production Reference: 1020910
Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK.
ISBN 978-1-847199-18-8
www.packtpub.com
Cover Image by Harmeet Singh ( <[email protected]> )
Author
Ruth Hoffman
Reviewers
Adrian Crum
Shi Jinghai
Acquisition Editor
Chaitanya Apte
Development Editor
Rakesh Shejwal
Technical Editor
Vanjeet D'souza
Indexer
Hemangini Bari
Editorial Team Leader
Mithun Sehgal
Project Team Leader
Ashwin Shetty
Project Coordinator
Joel Goveya
Proofreader
Jonathan Todd
Graphics
Geetanjali Sawant
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
Ruth Hoffman is an OFBiz evangelist with over 25 years of information technology experience, including stints in software design and development, training, project management, product marketing, and software sales, She has dedicated the last few years of her eventful career to furthering the OFBiz vision. Whether it be writing about OFBiz, providing implementation and OFBiz consulting services, or just "kicking the OFBiz tires" for each new release, she enjoys working with and telling the world about all that this amazing ERP software suite has to offer.
Ruth's current passion is her quest to provide high quality, cost effective OFBiz training and documentation. She has pursued this quest through multiple channels, including the OFBiz website. She invites everyone to stop by, take a gander, and give some feedback at http://www.myofbiz.com
As a long-standing supporter of OFBiz, she has authored several other OFBiz titles, including OFBiz E-Commerce Out-Of-The-Box and The OFBiz Catalog Manager. For more information, please see: http://www.myofbiz.com.
I would like to thank my partner, JC, for being so patient and understanding, my daughter for not getting too upset when I cancelled our planned Lilac Festival adventure, and my dog Sadie for sitting by me all those long hours when no one else would.
Also, my sincerest thanks go to Adrian Crum and Shi Jinghai for their dedicated efforts in providing technical reviews of this book. Thanks for keeping me honest and setting me straight on a number of occasions. Your contributions are greatly appreciated!
Adrian Crum is an IT Manager/Computer programmer for a company that builds homes. Prior to that, he owned and operated a computer retail/service/consulting business. He was Technical Editor of Coast Compute Magazine, and a contributing writer for Programmer's Journal. Adrian has been involved with the Apache OFBiz project as a contributing programmer since 2004, and he is a member of the Project Management Committee. His extensive experience in many programming languages and cross-platform development has been a key part of his contributions to the Apache OFBiz project.
Shi Jinghai graduated from Tsinghua University in 1991. In 2001, he took part in the China 2G Citizen Card Project and became an important system designer of the National Citizen Identity Information System of China. In 2004, he started his own company (Beijing Langhua Ltd.) focusing on IT services based on some excellent open source projects such as OFBiz, OpenCms, JBoss Portal, and Jasig CAS among others.
This book is designed to be read in any order, and is a collection of recipes found, by experience, to be most useful for developers working with the OFBiz project. Let it be your guide to enhancing your OFBiz productivity by saving you valuable time. Written specifically to give clear and straightforward answers to the most commonly asked OFBiz questions, this compendium of OFBiz recipes will show you everything you need to know to get things done in OFBiz.
Whether you are new to OFBiz or an old pro, you are sure to find many useful hints and handy tips here. Topics range from getting started, to configuration and system setup, security and database management, through the final stages of developing and testing new OFBiz applications. We are now Open For Business.
Chapter 1, Getting Started: If you already know how to get started with OFBiz then you can confidently skip this chapter. If, however, you are new to OFBiz, then you may find helpful hints in here to get you started, including getting a copy of the code from the download page or from the Subversion source code repository; fixing installation-related IP port collision errors; setting JAVA_HOME; fixing Java "Class Not Found" errors; installation verification; running JUnit tests; and some basic project artifact navigation hints, including where certain special directories (folders for Windows users) and files may be found.
Chapter 2, Java Development: OFBiz Java development starts with a clear understanding of the role of the Java CLASSPATH. In this chapter, learn how the CLASSPATH enables compilation and runtime loading of OFBiz artifacts. In addition, this chapter reveals how the OFBiz Java file-naming convention is helpful in organizing and finding Java source code. Also learn how to create OFBiz Events and Services, effectively use the provided Java debugging methods, call another OFBiz Service from within a Java program, access HTTP/HTTPS request parameters, use existing tools to handle error messages, use Java properties files, send e-mail using existing OFBiz Service(s), and manipulate XML documents using provided tools.
Chapter 3, The User Interface: Users interact with OFBiz—that is, the "User Interface"—through web pages often referred to within the project as "screens" or "screen views". In this chapter, see how web pages are built from the OFBiz Screen widget, including how to add actions, HTML markup, CSS, and other widgets (Tree, Menu, and Form widgets) to a single screen view widget definition. If your tastes run more towards creating your own screen views, see how to use FreeMarker templates inside Screen widget definitions to build (HTML) web pages. Also discussed in this chapter: passing parameters from the Screen widget's runtime context to the FreeMarker rendering engine, writing JavaScript and including it in a FreeMarker template, calling OFBiz Java methods directly from the FreeMarker context, forcing FreeMarker to render content with HTML markup at runtime, and how to upload a file—that is, support multipart HTML forms—in FreeMarker.
Chapter 4, OFBiz Services: OFBiz "Services" are reusable snippets of code that represent business processing or other logic. You write an OFBiz Service one time and invoke it anytime, anywhere and as often as needed. In this chapter, discover how to manage existing Services, invoke Services from an HTML form, and implement your own Service. Learn how Services communicate and interact during runtime operations using input and output attributes and triggers called Service Event Condition Actions, or SECAs. See best practices for handling errors within a Service and/or SECA. Also discussed are tips on implementing Services in languages other than Java, and a quick introduction to special SECA for incoming e-mail and operations on specific entities.
Chapter 5, The OFBiz Entity Engine: The OFBiz Entity Engine is the magic behind the database agnostic, data-driven tour-de-force that is OFBiz. In this chapter, see how to configure and use the Entity Engine to your advantage. Specifically, see how to change from the default Derby database to another database (note: throughout the OFBiz documentation, the term "data source" is used interchangeably with "database"); how to connect to remote and multiple databases; how entity groups work to help OFBiz organize access to multiple databases; and disable some system database startup checks, map new database field types, create your own entity definition file and entity definition, modify an existing entity definition—often referred to as the entity's model—and build view-entities that represent SQL join statements.
Chapter 6, OFBiz Security: What book about enterprise software would be complete without a word concerning security? In this chapter, get a quick introduction to securing your OFBiz instance, including recipes to lock down communication ports, disable demonstration accounts, protect web pages and web applications using OFBiz Security Groups, enable support for "tarpitting", retrieve forgotten passwords, change existing passwords, handle SSL certificates, and use OFBiz single sign-on support by way of the "external login key" feature.
Chapter 7, WebTools: Often lost in the OFBiz shuffle is a discussion covering basic usage of the many and varied tools that come with the project to manage your OFBiz instance. Collectively called "WebTools", this chapter looks at several important tasks easily accomplished using WebTools, including managing the cache, configuring system and application log tool settings for debug and troubleshooting support; exporting and importing database data; managing localization labels, and accessing databases using the SQL processor tool. Also discussed are introductions to the immensely useful Entity Reference Tool, finding and viewing OFBiz usage statistics, tracing OFBiz artifact dependencies, and working with temporal expressions.
Chapter 8, Web Services: With service orientation at the core of the OFBiz architecture, OFBiz is uniquely qualified to act as both a web services client and service provider for any number of web service interactions. In this chapter, learn how to act as a web services client and request service using URL parameter passing, HttpClient and XML document exchanges, and XML-RPC service requests. If you wish to provide web services, see how to set up OFBiz to serve XML-RPC services, generate and serve WSDL documents, and build both SOAP-based clients and services.
Chapter 9, OFBiz Tips and Tricks: This chapter is a collection of recipes that don't fit under other topic areas. Included here are hints on what to do if you run out of memory during OFBiz execution, reloading/reinitializing the OFBiz database, creating a new administrative user login and password, and getting the OFBiz version number (from Subversion checkouts or trunk builds only). Also included here are hints on using the provided ANT build tool to build an entire OFBiz instance, build a single OFBiz Component, and create a new OFBiz Component or Application. If you are looking for tips on creating a FreeMarker transformation, preparing data using Groovy, how to pop-up a new browser window, and OFBiz visual themes, you will find useful information here.
Appendix, Entity Engine by Example: In this Appendix, see how to effectively use the OFBiz Entity Engine to bring your OFBiz data drive applications to life. From the provided example data model, learn how to create entities and view-entities (SQL join statements) to implement a data model. Also, see how to read, remove, and write data to/from the database using the Entity Engine API; and use the provided EntityUtil API to manipulate database result-sets, access the automatic sequence generator to create new and unique sequence values, and see at a glance valid values for use with the Entity "Operator".
To run the recipes mentioned in this book, you will need the following software:
If you are an OFBiz user who has some familiarity with enterprise software systems and, perhaps more importantly, Internet and web exposure, you will be able to glean useful information from this book. For following some recipes, you will need only basic knowledge of modern browser behavior (for example, how to click a mouse button) while others assume only a passing familiarity with a text-editor and XML documents. If you are a software developer looking for Java and/or Groovy examples, this book also includes a chapter on Java software development.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "Add one or more delegator elements to the datasource object".
A block of code is set as follows:
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Use the WebTools Entity Reference - Interactive Version to see if the new view-entity was successfully created".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com, or e-mail <[email protected]>.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
The OFBiz project is a collection of hundreds of directories and files, organized to allow for easy download, start-up, customization, and enterprise deployment.
In this chapter, we shall look at a number of commonly performed tasks related to setting up and running with OFBiz, including:
OFBiz appeals to a remarkably diverse audience because of the breadth of solutions it enables. Whether you are a software developer or a business owner, you will find much to surprise, delight, and, most importantly use for your next enterprise software endeavor under the OFBiz umbrella.
In fact, there is so much to OFBiz that it is often difficult to know where to start. Unlike learning HTML or Java, OFBiz has no specification or authoritative source acting as the final arbiter of what works or is "correct". Rather, OFBiz is a well organized collection of "artifacts" that may, at the user's discretion, be mixed, matched, reorganized, and augmented with new artifacts to arrive at just about any business solution imaginable.
Just imagine an open source software project that includes:
With all the possibilities that OFBiz brings to the table, where does one begin? From experience, the best way to get up and running quickly is to download the project code and start kicking the "tires". Use some of the suggestions in this book to help quickly experience some of the state-of-the-art tools, utilities, and complete Applications that are part of OFBiz out-of-the-box.
Always remember: there is no "right" or "wrong" way to doing anything with OFBiz.
Everything you need to get up and running quickly and with minimum fuss is packaged with the OFBiz distribution. That includes an integrated database, a ready to use web server, and all the network and communications infrastructure necessary to be up and running in minutes. All you need to do before you download OFBiz is:
How do you know which version of Java to install? The following table summarizes available download options and necessary Java prerequisites:
Download title
Recommended usage
Minimum Java version
OFBiz version
apache-ofbiz-09.04.zip
Recommended for new users and those looking for the most stable project package.
Java 1.5
*
apache-ofbiz-4.0.zip
Legacy release. Not recommended for new users.
Java 1.4 or Java 1.5
"Nightly Trunk Builds"
ofbiz-trunk-current.zip
Project committers or users needing latest code. May not be stable or thoroughly tested!
These files are available on the "snapshots" download page.
Java 1.6
* *
Nightly trunk builds do not have release numbers.
* Nightly builds and version numbers represent bug fixes only.
* * "trunk" versions before January 2010, Java 1.5
Once OFBiz is downloaded and available locally on your hard drive, install it by "unpacking" it with your operating system's "unzip" tool.
Once unzipped, OFBiz is ready to run.
Looking for the Java SDK?
Most Java SDKs are available from Sun Microsystems at:
http://www.java.com/
MAC users will need to contact Apple directly or use the Software Update feature available on the Apple menu.
Because OFBiz is more than just a few randomly organized files and directories, the collective and organized resources that go into making OFBiz, including the Apache infrastructure and software developers, are often called the "Project". The OFBiz project generates OFBiz code that is stored in a Subversion source code repository. It is a release and version of this code, extracted from the source code repository, built, and packaged using a "zip" archive tool, that we download as an OFBiz user.
Decide which version to download. It is recommended that new users download OFBiz Release 9.04. Experienced users and those wishing to contribute back to the project should consider starting with the latest version of the OFBiz source code "trunk". This code may be found on the Apache OFBiz "snapshot" web page.
Ensure you have the following necessary prerequisites in place:
Apache OFBiz can be downloaded as shown in the following steps:
Note: The official OFBiz download website is often in a state of flux. At times, you may be directed to a mirror site before you are allowed to download any code. On other occasions, clicking the OFBiz download file will directly initiate the download. If you find this all very confusing, you are not alone. Feel free to comment on the official OFBiz mailing list and voice your opinion. More information about the OFBiz user mailing lists may be found here: https://cwiki.apache.org/confluence/display/OFBADMIN/Mailing+Lists
OFBiz is packaged to include everything you need to run right out-of-the-box. Once your download is on your desktop, all you need do is unbundle it, build the distribution using the provided ANT tool, and start it up. No other configuration steps are necessary.
There are a number of ways to start up OFBiz. Depending on your operating system environment and your proclivities towards working on the command line, you may:
Windows
Unix
Command line
startofbiz.bat
startofbiz.sh
java -Xmx256M -jar ofbiz.jar
ant run
OFBiz runs inside and depends on a JVM. Before OFBiz can even start up, the JVM must be operational. The distribution provides all the tools necessary in the form of startup scripts to get the JVM up and running without any further work on your part.
For the curious, the following summarizes the OFBiz start-up sequence. This information is useful if you ever want to integrate third-party code or add your own Java programs to the OFBiz mix:
For more information on prerequisites, getting the OFBiz code, and downloading and starting OFBiz up, please visit the What Do I Get? section on the following OFBiz web page: http://ci.apache.org/projects/ofbiz/snapshots/
Note: Be careful not to use the DOWNLOAD OFBIZ button on the snapshots download web page. Unless you want to download the latest OFBiz trunk nightly build, this button should not be confused with the DOWNLOAD OFBIZ button found on the official OFBiz loading web page: http://ofbiz.apache.org
If you are planning to contribute back to the project or are just curious about downloading from the OFBiz source code control system, you may download a complete OFBiz package from the Subversion source code repository using the following procedure.
You will need a Subversion client, or an IDE with a Subversion client installed in order to access and download from Subversion.
Before you can download directly from the OFBiz Subversion repository, you must first have a Subversion client installed locally. Subversion clients come in several forms. The Subversion software comes with a command-line client and a command-line tool that facilitates checkout and download from a Subversion repository. This command is the co command.
Some users prefer to use built-in IDE (Integrated Development Environment) Subversion clients. One such client, Subclipse (http://subclpse.tigris.org), allows the user to checkout and install OFBiz from within the IDE using IDE-specific commands.
It goes without saying: you must also have an Internet connection with access to the OFBiz Subversion repository.
OFBiz source code can be downloaded from the Subversion repository by the following steps:
OFBiz project source code is saved in a repository managed by the Subversion source code control system. Subversion uses a tree-like structure to organize and group together project artifacts, including source code. Each time a project developer commits an artifact to the repository, a new OFBiz version number is created, similar to a leaf on a tree. The project has had thousands of commits over its lifetime, hence the current version number is well on its way towards one million.
To request a version of OFBiz from the repository, a user issues a Subversion checkout command, co. A Subversion checkout fetches by default the latest leaf or version of the project from the Subversion code tree.
The OFBiz source code repository contains all previous versions of OFBiz. You may checkout any version at any time. Additionally, you may checkout "releases" of OFBiz where a "release" is a "branch" of the source code tree, by indicating your desire using the co command options.
Once the fetch from the repository is complete, you must run the OFBiz build script to build the project before running the OFBiz startup scripts. The build script rebuilds all included Java programs, rebuilds the runtime CLASSPATH, and checks and loads the database with seed and demonstration data.
For more information on using Eclipse with the OFBiz Subversion repository, please refer to the following OFBiz Wiki page:
http://cwiki.apache.org/confluence/display/OFBIZ/Running+and+Debugging+OFBiz+in+Eclipse
For more information on Subversion, please refer to the Subversion website located at:
http://subversion.tigris.org
One of the most common OFBiz startup errors involves IP port collisions. OFBiz requires several Internet Protocol (IP) ports to run. All OFBiz downloads have these ports set to default values so that you may start up OFBiz without further configuration.
Occasionally, these default values are in conflict with IP ports used by other software already running on your system. If OFBiz cannot acquire the ports it needs to run, it will immediately shutdown and you will receive an error similar to the following on the command line (from which you started OFBiz):
To remedy IP port conflicts, you may either turn off the software using the ports OFBiz needs or you can change the OFBiz configuration so that it uses ports not used by other software.
To change the OFBiz IP port configuration, perform the following:
For example, to fix collisions on port 8080, the IP port that OFBiz listens on for HTTP requests, navigate to the ofbiz-containers.xml file as shown in the following figure and change the value for port 8080 to another port not in use.
Note: Setting the HTTP port to a value between 1-1024 may require operating system administrative privileges in order to start up OFBiz. This is a constraint placed on these ports outside the control of OFBiz.
The following is a list of IP port configuration file locators for reference:
Port #
Configuration file location relative to install directory
Port usage note
8080
~framework/base/config/ofbiz-containers.xml
Tomcat HTTP listener
~framework/webapp/config/url.properties
Internal HTTP port *
8443
~framework/base/config/ofbiz-containers.xml
Tomcat HTTPS listener
~framework/webapp/config/url.properties
Internal HTTPS port *
8009
~framework/base/config/ofbiz-containers.xml
AJP connector
9990
~framework/base/config/ofbiz-containers.xml
BeanShell remote telnet port
9991
~framework/base/config/ofbiz-containers.xml
