Scala UDF:java.lang.NoClassDefFoundError:scala / ScalaObject

时间:2013-01-02 17:36:23

标签: scala user-defined-functions apache-pig

我正在尝试将Scala用于UDF,但Pig作业失败了 错误“java.lang.NoClassDefFoundError:scala / ScalaObject”。我做错了什么?

$ cat NonEmpty.scala

package nonempty

import org.apache.pig.FilterFunc
import org.apache.pig.data._

class NonEmpty extends FilterFunc {
  def exec(input: Tuple) = {
    val s = input.get(0)
    s match {
    case a: String => !a.isEmpty 
    case _ => false
   }
  }
}

$ cat ex3.pig

register ./nonempty.jar 
register ./scala-library.jar;

define NonEmpty nonempty.NonEmpty();

raw = load 'excite-small.log' using PigStorage('\t') as (user: chararray, time:chararray, query: chararray);

locations = filter raw by NonEmpty(query);

构建:

scalac -cp ~/pig-0.9.2/pig-0.9.2.jar NonEmpty.scala
jar -cf nonempty.jar nonempty

Pig Stack Trace:

2 ---------------
3 ERROR 2998: Unhandled internal error. scala/ScalaObject
4 
5 java.lang.NoClassDefFoundError: scala/ScalaObject
(...)

1 个答案:

答案 0 :(得分:5)

ScalaObject位于scala-library.jar中,需要包含在运行时类路径中。因此,将scala-library.jar添加到运行该程序的命令的运行时类路径中。