9

I am receiving the following error java.lang.NoClassDefFoundError: org/apache/commons/collections/Transformer trying to use BeanMap from the Apache Commons BeanUtils library.

It is generated from the following code: BeanMap studentBeanMap = new BeanMap(cohortStudentData.get(row)); where cohortStudentData is a list of beans.

I am using BeanListHandler from Apache DBUtils to form the list of beans from a database.

I understand from this and this bug report that BeanMap is dependant on the Apache Collections framework. However, I have imported all relevant libraries into my project and into my class, as you can see below:

External Library List

Import Statements

Does anyone know why this might be happening?

Ben
  • 843
  • 2
  • 9
  • 20
  • 2
    You need an older version of `commons-collections`. Currently you are using `commons-collections4` (note the 4 here) - but the exception tells you that `org.apache.commons.collections.Transformer` (no 4 in here) is required. Try an download version `commons-collections-3`. – fateddy Feb 28 '15 at 05:23

5 Answers5

11

I am not really sure, but i think your error is because of jar versions. Lately apache has changed the package of the new versions of their jars because they implement new functionality or something that is not fully backward compatible. For example the jar commons-beanutils-1.9.2.jar depends on commons-collections-3.2.1.jar (according to this site) and you are using commons-collections-4.4.0.jar. If you are planning using the universe of apache jars, you need to be sure that they are all compatible.

Ivan Perales M.
  • 347
  • 4
  • 11
9

Just add this dependency to your project.

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.2</version>
    </dependency>
zygimantus
  • 3,649
  • 4
  • 39
  • 54
2

commons-collections4-x.x.jar Add the library to your classpath and try to run again. It will work.

Download the library from: https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.1

1

Adding dependency of version 3.2.1 seems working here

<dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>3.2.1</version>
</dependency>
thedevd
  • 683
  • 11
  • 26
  • 1
    Not a safe solution as there is a known [vulnerability](https://www.cvedetails.com/version/187982/Apache-Commons-Collections-3.2.1.html) in that version. The suggestion is to move to 3.2.2 or [commons-collections4-4.2](https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.2). – smos Aug 08 '18 at 11:53
0

Add commons-collections-3.2.jar to library of the project

Yoshita Mahajan
  • 443
  • 4
  • 6