title: java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
body: <p>I am getting a <code>java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream</code> when tring to upload a file to my server runnning on localhost. This is the servlet I am using:</p>
  
  <pre><code>@WebServlet("/UploadServlet")
  public class UploadServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  private String UPLOAD_DIRECTORY = "~/EclipseProjects/DocSearch/uploads";
  
  /**
   * @see HttpServlet#HttpServlet()
   */
  public UploadServlet() {
      super();
  }
  
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  }
  
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      if(ServletFileUpload.isMultipartContent(request)) {
          try {
              List&lt;FileItem&gt; multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
              for(FileItem item: multiparts) {
                  if(!item.isFormField()) {
                      String name = new File(item.getName()).getName();
                      item.write(new File(UPLOAD_DIRECTORY + File.separator + name));
                  }
              }
              request.setAttribute("message", "File uploaded successfully");
          } catch (Exception ex) {
              request.setAttribute("message", "File upload failed due to: " + ex);
          }
      } else {
          request.setAttribute("message", "Sorry this servlet only handles file upload requests");
      }
      request.getRequestDispatcher("/result.jsp").forward(request, response);
  }
  
  }
  </code></pre>
  
  <p>I have already added commons-fileupload-1.2.2.jar into the WEB-INF/lib folder. I have tried creating a new server and running the project on it, tried re-downloading the jar file from different sources, but none of them seems to solve my problem.</p>
  
  <p>Note:</p>
  
  <p>I have already gone through:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/11154252/how-to-solve-this-java-lang-noclassdeffounderror-org-apache-commons-io-output-d">How to solve this java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream?</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/20091687/javax-servlet-servletexception-java-lang-noclassdeffounderror-org-apache-commo">javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/5342241/fileupload-deferredfileoutputstream-class-not-found">FileUpload: DeferredFileOutputStream class not found?</a></p></li>
  </ul>