FileUpload: DeferredFileOutputStream class not found? [duplicate]
Asked Answered
P

2

8

I'm using apache FileUpload to handle a.. file upload. I'm using it with jetty. The servlet sees the multipart request, but throws a NoClassDefFoundError exception upon execution:

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
  throws ServletException, IOException 
{
  boolean isMultipart = ServletFileUpload.isMultipartContent(req);
  if (isMultipart) {
    try {
      FileItemFactory factory = new DiskFileItemFactory();

      ServletFileUpload upload = new ServletFileUpload(factory);

      List items = upload.parseRequest(req); //  exception
      ...

throws:

java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
   at org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199)

caused by:

java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream

Is there an additional jar we need to include besides commons-fileupload-1.2.2.jar?

My goal is to just upload a single file and write it to disk.

Thanks

Phio answered 17/3, 2011 at 16:39 Comment(0)
R
14

You need to add CommonsIO to the classpath. Commons File Upload is dependent on it.

Recession answered 17/3, 2011 at 16:43 Comment(1)
maven repo: mvnrepository.com/artifact/org.apache.commons/commons-ioDwayne
M
4

Add the below dependency

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>
Microphyte answered 16/9, 2015 at 21:15 Comment(1)
To see another versions access link: mvnrepository.comTrudietrudnak

© 2022 - 2024 — McMap. All rights reserved.