开发者

FileUpload: DeferredFileOutputStream class not found? [duplicate]

开发者 https://www.devze.com 2023-02-17 06:33 出处:网络
This question already has answers here: How to solve this java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream?
This question already has answers here: How to solve this java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream? (6 answers) Closed 6 years ago.

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.isMultipart开发者_开发问答Content(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


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


Add the below dependency

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>
0

精彩评论

暂无评论...
验证码 换一张
取 消