Flink java.lang.ClassNotFoundException:play.api.libs.json.Reads

时间:2016-06-10 11:40:48

标签: scala apache-flink flink-streaming

我正在编写一个从文本文件中读取并将每一行解析为Json的代码,但是Flink(1.0.3 - 具有2个Taskmanagers的集群)中的工作失败了,除了java.lang.ClassNotFoundException: play.api.libs.json.Reads < / p>

我的代码:

import org.apache.flink.streaming.api.scala._
import play.api.libs.json.Json
import org.joda.time.{DateTime, DateTimeZone}

object rabbitjob {

case class MyJson(pr: Long,
                dv: Long,
                ty: Int,
                cr: String,
                rc: String,
                vl: Boolean,
                ss: String,
                id: Long
               )

def main (args:Array[String]){
  val env = StreamExecutionEnvironment.getExecutionEnvironment
  val stream = env.readTextFile("hdfs:///test/ignicion.io")

  implicit val myJsonReads = Json.reads[MyJson]

  def jsontr(cuerpo: String): Unit ={

     val inputJson = Json.parse(cuerpo)
     val myJsonInstance: MyJson = inputJson.as[MyJson]

     println(DateTime.now(DateTimeZone.UTC).getMillis() + " " +  myJsonInstance.cr + " " + matchtype(myJsonInstance.ty) + " " + " " + matchvalue(myJsonInstance.vl))

  def matchtype (x: Int): String = x match{
      case 1 => "Door"
      case 2 => "Window"
      case _ => "otros"
    }

  def matchvalue (x: Boolean): String = x match{
      case true => "ON"
      case false => "OFF"
    }
  }

  println(stream)
  stream.map(jsontr(_))

 env.execute("Test Rabbit")
 }
}

有什么想法吗?提前谢谢

1 个答案:

答案 0 :(得分:0)

您需要将所有外部依赖项与Flink程序一起打包到您提交给群集的“胖”JAR文件中。

Flink文档显示了如何使用Maven