简体   繁体   中英

java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.read with Tika (detect method)

Here is my method:

public String retrieveMimeType(InputStream stream, String filename) throws Exception {
         TikaConfig config = TikaConfig.getDefaultConfig();
         Detector detector = config.getDetector();

         TikaInputStream streams = TikaInputStream.get(stream);

         Metadata metadata = new Metadata();
         metadata.add(TikaCoreProperties.RESOURCE_NAME_KEY, filename);
         MediaType mediaType = null;
        mediaType = detector.detect(stream, metadata);
        return mediaType.toString();
    }

It give me this on the log:

java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.read(Ljava/io/InputStream;[B)I
    at org.apache.tika.detect.apple.BPListDetector.detect(BPListDetector.java:106)
    at org.apache.tika.detect.CompositeDetector.detect(CompositeDetector.java:85)
    at com.hraccess.helper.UserFileValidator.retrieveMimeType(UserFileValidator.java:313)
    at com.hraccess.webclient.servlets.ServletBlob.doPost(ServletBlob.java:429)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)

For this line:

at com.hraccess.helper.UserFileValidator.retrieveMimeType(UserFileValidator.java:313)

here is the line 313:

mediaType = detector.detect(stream, metadata);

So what can I do? It gives this error when I added the parsers to my pom.xml. How to find why?

The stacktrace says that org.apache.commons.io.IOUtils.read is missing. This is a static method in org.apache.commons.io.IOUtils , which class is part of thecommons-io package.

  1. Make sure that commons-io is linked into your app (check the pom.xml, or an mvn dependency:tree output).

  2. Make sure it is linked in a relative newer version. V2.0 of the commons-io did not have this method yet ( link ), but the current one already has ( link ). In general, it is a good practice to use always the last stable version of everything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM