How to solve this java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream?
The particular exception message is telling you that the mentioned class is missing in the classpath. As the org.apache.commons.io
package name hints, the mentioned class is part of the http://commons.apache.org/io
project.
And indeed, Commons FileUpload has Commons IO as a dependency. You need to download and drop commons-io.jar
in the /WEB-INF/lib
as well.
See also:
- How to upload files to server using JSP/Servlet?
- How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
- How do I import the javax.servlet API in my Eclipse project?
use maven dependency
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
or download commons-io.1.3.2.jar to your lib folder
Solution
By default, Struts is using Apache “commons-io.jar” for its file upload process. To fix it, you have to include this library into your project dependency library folder.
- Get Directly
Get “commons-io.jar” from official website – http://commons.apache.org/io/
- Get From Maven
The prefer way is get the “commons-io.jar” from Maven repository
File : pom.xml
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>