The import org.apache.commons cannot be resolved in eclipse juno

user2024438 picture user2024438 · Jan 30, 2013 · Viewed 167.6k times · Source

I having the problem while compiling the my project in eclipse. It was shoving the error The import org.apache.commons cannot be resolved.

enter image description here

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

Answer

BalusC picture BalusC · Jan 30, 2013

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?