简体   繁体   中英

Playframework 2.x Apache Tika issue

i am uploading file using upload from then after getting uploaded file i am using Apache tika top extract content,metadata from uploaded file and applying but some error is coming

have a look of my playframework controller code :

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());
    }

but when i am running this web application i am using 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

it is giving error :

if you want to see full error then full error

and some of error is :

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

i added tika jar file.

Give me some idea to fix this issue.

Adding a dependency to Playframework can be done in two ways :

  1. Unmanaged dependencies : directly add the jar in a /lib folder at the root of your project and restart your play application.

  2. Managed dependencies : Add the jar to your build.sbt file as in the following example :

     val appDependencies = Seq( jdbc, cache, "org.apache.tika" % "tika" % "0.3" ) 

我认为您还需要添加tika-parsers-XYjar文件(其中XY是版本,例如1.4)。

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