39

I am having a problem while compiling my project in Eclipse. It is showing the error The import org.apache.commons cannot be resolved.

enter image description here

Please tell me what does this error means and how to solve it.

Will
  • 19,789
  • 10
  • 43
  • 45

8 Answers8

31

The mentioned package/classes are not present in the compiletime classpath. Basically, Java has no idea what you're talking about when you say to import this and that. It can't find them in the classpath.

It's part of Apache Commons FileUpload. Just download the JAR and drop it in /WEB-INF/lib folder of the webapp project and this error should disappear. Don't forget to do the same for Apache Commons IO, that's where FileUpload depends on, otherwise you will get the same problem during runtime.


Unrelated to the concrete problem, I see that you're using Tomcat 7, which is a Servlet 3.0 compatible container. Do you know that you can just use the new request.getPart() method to obtain the uploaded file without the need for the whole Commons FileUpload stuff? Just add @MultipartConfig annotation to the servlet class so that you can use it. See also How to upload files to server using JSP/Servlet?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Ah jesus.. man I have been looking around and around for about 45 minutes.. and your post helped! Was putting it into a lib folder that was external to the /WEB-INF/ before. Argh! Thanks! – Nate Uni Sep 05 '14 at 06:42
  • Can you send the llink to download the JAR files you are talking about in the answer – Tejesh Raut Dec 01 '15 at 14:40
  • @Tejesh: Just click at "Download" link at the linked homepages, or click the related question link in bottom of the answer. – BalusC Dec 01 '15 at 14:51
8

If you got a Apache Maven project, it's easy to use this package in your project. Just specify it in your pom.xml:

<project>
...

    <properties>
        <version.commons-io>2.4</version.commons-io>
    </properties>

    <dependencies>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${version.commons-io}</version>
        </dependency>
    </dependencies>

...
</project>
chenlian
  • 690
  • 6
  • 7
5

expand "Java Resources" and then 'Libraries' (in eclipse project). make sure that "Apache Tomcat" present.

if not follow- right click on project -> "Build Path" -> "Java Build Path" -> "Add Library" -> select "Server Runtime" -> next -> select "Apache Tomcat -> click finish

Deepak Gautam
  • 1,309
  • 12
  • 14
3

You could just add one needed external jar file to the project. Go to your project-->java build path-->libraries, add external JARS.Then add your downloaded file from the formal website. My default name is commons-codec-1.10.jar

Olivia Liao
  • 375
  • 3
  • 7
  • 2
    Could you please elaborate your answer a little. – Ashrith Nov 11 '14 at 02:41
  • Go to your project-->java build path-->libraries, add external JARS.Then add your downloaded file from the formal website. My default name is commons-codec-1.10.jar – Olivia Liao Nov 18 '14 at 01:23
1

Look for "poi-3.17.jar"!!!

  1. Download from "https://poi.apache.org/download.html".
  2. Click the one Binary Distribution -> poi-bin-3.17-20170915.tar.gz
  3. Unzip the file download and look for this "poi-3.17.jar".

Problem solved and errors disappeared.

yTze
  • 95
  • 6
1

You could also add the external jar file to the project. Go to your project-->properties-->java build path-->libraries, add external JARS. Then add your downloaded jar file.

ImportError
  • 358
  • 5
  • 17
  • 1
    Other than that, if you already have a JAR file within your project folder you may simply click on "add jar", then navigate through the folder/file "navigator/selector" (which is a GUI frame starting from jour project location) and select the jar(s). – Marco Ottina Jun 11 '22 at 15:56
0

In my little experience, I have solved the issue about org.apache.commons.cli, on my Eclipse Version: 2019-12 (4.14.0): Eclipse Project explorer

Java buid Path-->Add external Jar in the Classpath

The PATH, inside $HADOOP_HOME where is the file .jar

0

In Provar(2.8.0), Issue got resolved after adding the jar file(commons-io-2.11.0.jar) to the project.

Steps: 1.Download the latest JAR file from https://commons.apache.org/proper/commons-io/download_io.cgi

  1. Added jar file under lib folder in project. 2.Project--> Properties --> Java build path --> Libraries--Add Jars from lib folder.