我是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 $主要的$ 1.apply(App.scala:76)位于scala的scala.App $$ anonfun $ main $ 1.apply(App.scala:76)scala.collection.immutable.List.foreach(List.scala:381)。在TikaExtract.main的TikaExtract $ .main(TikaExtract.scala:9)的scala.App $ class.main(App.scala:76)中的collection.generic.TraversableForwarder $ class.foreach(TraversableForwarder.scala:35)(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.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:338)at java.lang .ClassLoader.loadClass(ClassLoader.java:357)... 11 more
我在这里做错了什么?