我在上传文件后使用上传上传文件我正在使用上传文件的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
它给出了错误:
如果你想看到完整的错误然后是完整的错误
一些错误是:
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 文件。
给我一些想法来解决这个问题。