hamideh
hamideh

Reputation: 225

Error: package org.apache.commons.collections15 does not exist

I'd like to run a java package for measuring quality of my community detection algorithm but I encounter following error:

Standalone.java:22: error: package org.apache.commons.collections15 does not exist 

It seems the package is not by default installed in java, since I already installed java using sudo apt-get install default-jdk and similar commands. I find the package in https://github.com/cloudera/collections-generic which contains collection 15. Java is not my programming language and I don't know how to install the package; should I place it in specific folder.

Upvotes: 0

Views: 16942

Answers (2)

Chris Maggiulli
Chris Maggiulli

Reputation: 3814

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.

Upvotes: 3

Monzurul Shimul
Monzurul Shimul

Reputation: 8386

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

<dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>3.0</version>
</dependency>

Upvotes: 6

Related Questions