org.apache.commons.collections15 is available in apache commons collection jar. You need to have the jar in your classpath.
If you are using maven then add this in your pom.xml
Copy<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.0</version>
</dependency>
Answer from Monzurul Shimul on Stack Overfloworg.apache.commons.collections15 is available in apache commons collection jar. You need to have the jar in your classpath.
If you are using maven then add this in your pom.xml
Copy<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.0</version>
</dependency>
Some Java background
Java has a concept referred to as library dependencies which (in this case) you can think of as extensions to Java's core API. In layman's terms they're self contained "units" of code that give you access to programmatic structures (methods, classes, interfaces, etc) that do not come defaualt in Java. Some additional information
- They are organized into packages (groupings of liked things) which are imported at the top of .java files that use them
- These packages are unique and as you see will usually be in the form of tld.companyname.projectname.subgroup1.subgroup2...etc (this guarantees uniqueness)
- They are also written in Java (usually)
- They need to be added to your classpath (a setting that identifies where you compiled code is)
- You can physically add them or use some type of build and dependency management tool like Maven, Ant Ivy, Gradle, etc.
Your specific case
The error in this case is telling us a few things. Firstly it is telling us that the error is occurring in the Standalone.java file on line 22. Additionally it is telling us that the issue is occurring because the Apache Commons library is no present. If you view the Standalone.java file you will see the following import on line 22
- import org.apache.commons.collections15.Transformer;
The general solution
A general solution to this problem depends solely on how you are building this application. In generally you need to do the following:
- First figure out if this program uses any dependency management tool. A pom.xml file indicates Maven, a build.xml file indicates ANT, etc. A quick search I do not see any tool being used. I would generally
- Download the Apache Commons library from https://commons.apache.org/
- Place the jar file in the /libs folder
- Add that jar to the classpath
The specific solution
In the projects root directory you will see a .classpath file. This file is generated by the Eclipse IDE that defines the projects classpath. This file should have an entry that somewhere points to the Commons jar file. On line 3 you will see the following classpath entry with these two pertinent attributes
- sourcepath="/home/reihaneh/.m2/repository/net/sourceforge/collections/collections-generic/4.01/collections-generic-4.01-sources.jar"
- path="libs/jung2-2_0_1/collections-generic-4.01.jar"
I believed the the issue here is with the sourcepath attribute. It is clearly assigned an absolute URI that is (presumably) not applicable to you. Try to assign it the same value as the path attribute.
You should fix import for CollectionUtils
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
public class main {
public static void main(String[] args) {
List<Integer> empty_list = new ArrayList<Integer>();
if (CollectionUtils.isEmpty(empty_list)) {
System.out.println("List is empty");
}
}
}
if you use IntelliJ IDEA - JetBrains. you should do this.
- In the Maven tool window, right-click a linked project.
- From the context menu, select Reload project .
Try with -classpath common-collections.jar in the command line.
Package name for collection is changed from collections to collections4 with latest jar file.
How I got into this issue and solved:
I upgraded jar version to commons-collections4-4.4.jar, and got into this error.
I changed import statement in my java file, which linked to new jar as follows
Error: import org.apache.commons.collections.map.HashedMap;
New (update): import org.apache.commons.collections4.map.HashedMap;
and error resolve. Hope it may help.
The error is "Cannot resolve commons-collections:commons-collections:2.1"
It has nothing to do with "commons-validator" dependency.
The commons collection artifact has moved to a different location in maven artifactory.
Please check this out https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
try to change version of your package, but better find dependency in https://mvnrepository.com/ which you need, copy this text and try to reimport.