我正在尝试将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
(...)
答案 0 :(得分:5)
ScalaObject
位于scala-library.jar
中,需要包含在运行时类路径中。因此,将scala-library.jar
添加到运行该程序的命令的运行时类路径中。