3.2. Obtaining Commons BeanUtils

Problem

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

Solution

You must download the latest version of Commons BeanUtils, and place the Commons BeanUtils JAR in your project’s classpath. Following the steps outlined in Recipe 1.1, download Commons BeanUtils 1.7 instead of Commons Lang.

Commons BeanUtils depends on Commons Logging 1.0.3 and Commons Collections 3.0; both of these can be downloaded from the same location as Commons BeanUtils.

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 Jakarta Commons. Unless specified otherwise, every utility mentioned in this chapter is from Commons BeanUtils.

If you have a Maven project that needs to use Commons BeanUtils, add a dependency on Commons BeanUtils 1.7 with the following section in project.xml:

<dependencies>
  <dependency>
    <id>commons-beanutils</id>
    <version>1.7</version>
  </dependency>

  ....other dependencies...
</dependencies>

The rest of this chapter focuses on Commons BeanUtils.

Get Jakarta Commons Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.