Apache TIKA中的PDF解析

我是Apache Tika的新手,并试图弄清楚如何使用它 . 我通过互联网阅读了一些博客,并试图解析PDF文件 . 我的Scala代码是:

import java.io.{File,FileInputStream}

import org.apache.tika.Tika
import org.apache.tika.parser._
import org.apache.tika.metadata._
import org.apache.tika.sax.WriteOutContentHandler
import org.apache.tika.parser.pdf.PDFParser

object TikaExtract extends App{
  val tika = new Tika()

  val file1 = new File("/home/user/Documents/aa.pdf")
  val stream = new FileInputStream(file1)

  val pdf = new PDFParser()
  val handler = new WriteOutContentHandler(-1)
  val metadata = new Metadata()
  val context = new ParseContext()
  pdf.parse(stream, handler, metadata, context)
  stream.close()
}

我得到的错误是:

线程“main”中的异常java.lang.NoClassDefFoundError:org / apache / jempbox / xmp / XMPSchema at TikaExtract $ .delayedEndpoint $ TikaExtract $ 1(TikaExtract.scala:15)at TikaExtract $ delayedInit $ body.apply(TikaExtract.scala: 9)scala.Function0 $ class.apply $ mcV $ sp(Function0.scala:34)at scala.runtime.AbstractFunction0.apply $ mcV $ sp(AbstractFunction0.scala:12)at scala.App $$ anonfun $ main $ 1 .apply(App.scala:76)at scala.App $$ anonfun $ main $ 1.apply(App.scala:76)at scala.collection.immutable.List.foreach(List.scala:381)at scala.collection . generic.TraversableForwarder $ class.foreach(TraversableForwarder.scala:35)at sca.App $ class.main(App.scala:76)at TikaExtract $ .main(TikaExtract.scala:9)at TikaExtract.main(TikaExtract.scala)引起:java.lang.ClassNotFoundException:org.apache.jempbox.xmp.XMPSchema at java.net.URLClassLoader.findClass(URLClassLoader.java:381)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun java.lang上的.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:338) . ClassLoader.loadClass(ClassLoader.java:357)......还有11个

我在这做什么错?

回答(0)