Common Java Cookbook

Edition: 0.19

Download PDF or Read on Scribd

Download Examples (ZIP)

3.2. Obtaining Commons BeanUtils

3.2.1. Problem

You want to use Commons BeanUtils to manipulate and access simple, indexed, and nested bean properties.

3.2.2. Solution

To use Commons BeanUtils in a Maven 2 project, add the following dependency to your project's pom.xml:

Example 3.2. Adding a Dependency on Commons BeanUtils

    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <version>1.8.0</version>
    </dependency>

If you are not sure what this means, I'd suggest reading Maven: The Definitive Guide. When you depend on a library in Maven 2, all you need to do is add the dependency groupId, artifactId, and version to your project's dependencies. Once you do this, Maven 2 will download the dependency and make it available on your project's classpath.

3.2.3. Discussion

Commons BeanUtils is a collection of utilities that makes working with beans and bean properties much easier. This project contains utilities that allow one to retrieve a bean property by name, sort beans by a property, translate beans to maps, and more. BeanUtils is simple and straightforward, and, as such, you will find that it is one of the most widely used and distributed libraries in open source Java. Along with Commons Lang and Commons Collections, Commons BeanUtils is part of the core of Apache Commons. Unless specified otherwise, every utility mentioned in this chapter is from Commons BeanUtils.

3.2.4. See Also

To learn more about Commons BeanUtils, visit the Commons BeanUtils web site: http://commons.apache.org/beanutils/.


Creative Commons License
Common Java Cookbook by Tim O'Brien is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
Permissions beyond the scope of this license may be available at http://www.discursive.com/books/cjcook/reference/jakartackbk-PREFACE-1.html. Copyright 2009. Common Java Cookbook Chunked HTML Output. Some Rights Reserved.