我从上传文件开始使用上传文件上传,然后从上传文件中使用Apache tika
顶部提取content,metadata
并应用,但是会出现一些错误
看一下我的playframework控制器代码:
public static Result upload() {
MultipartFormData body = request().body().asMultipartFormData();
FilePart picture = body.getFile("doc");
if (picture != null) {
String fileName = picture.getFilename();
int eof = fileName.lastIndexOf('.');
String ext = fileName.substring(eof + 1);
file = picture.getFile();
InputStream is;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Parser ps=new AutoDetectParser();
BodyContentHandler bch=new BodyContentHandler();
Metadata metadata=new Metadata();
try {
ps.parse(is, bch, metadata, new ParseContext());
} catch (IOException | SAXException | TikaException e) {
e.printStackTrace();
}
String sw=bch.toString();
return ok(sw+" entity extracted and saved" + ext);
}else {
flash("error", "Missing file");
return redirect(routes.Application.index());
}
但是当我运行此Web应用程序时,我正在使用
commands
:rahul@inext:~/playframwrk apps/EntWebPrj$ play
[info] Loading project definition from /home/rahul/playframwrk apps/EntWebPrj/project
[info] Set current project to EntWebPrj (in build file:/home/rahul/playframwrk%20apps/EntWebPrj/)
_ _
_ __ | | __ _ _ _| |
| '_ \| |/ _' | || |_|
| __/|_|\____|\__ (_)
|_| |__/
play! 2.1.2 (using Java 1.7.0_25 and Scala 2.10.0), http://www.playframework.org
> Type "help play" or "license" for more information.
> Type "exit" or use Ctrl+D to leave this console.
[EntWebPrj] $ ~run
它给出了错误:
如果您想看到完整的错误,请full error
和一些错误是:
sbt.PlayExceptions$CompilationException: Compilation error[error: package org.apache.tika.exception does not exist]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun$apply$16.apply(PlayReloader.scala:349) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun$apply$16.apply(PlayReloader.scala:349) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(PlayReloader.scala:349) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(PlayReloader.scala:346) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
[warn] play - No application found at invoker init
我添加了tika jar文件。
给我一些想法来解决此问题。
最佳答案
可以通过两种方式向Playframework添加依赖项:
非托管依赖项:直接将jar添加到项目根目录的/ lib文件夹中,然后重新启动播放应用程序。
托管依赖项:如以下示例所示,将jar添加到build.sbt文件:
val appDependencies = Seq(
jdbc, cache,
"org.apache.tika" % "tika" % "0.3"
)
关于java - Playframework 2.x Apache Tika问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18360570/