Scala IDE抛出java.lang.NoClassDefFoundError:org / codehaus / janino / JaninoRuntimeException

时间:2018-01-17 16:46:46

标签: eclipse scala apache-spark spark-dataframe

当我尝试在Scala IDE(Eclipse Version 4.7)中执行spark代码时,我获得了Spark DataFrame代码的Runtime Exception。

import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.sql.SQLContext
object Demo {
  def main(args:Array[String]){
    val conf=new SparkConf().setAppName("Local App").setMaster("local[2]")
    val sc=new SparkContext(conf)
    val spark=new SQLContext(sc)
    import spark.implicits._
    val data =Seq((1,"ab"),(2,"abc"))
    val dataRDD=sc.parallelize(list)
    val df=dataRDD.toDF()
    df.show() // Getting Exception here
  }
}

当我使用spark-shell执行时,上面的代码工作正常。但问题是当我使用Scala IDE时。我正在使用Mac OS。异常消息和POMbelow:

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/janino/JaninoRuntimeException
    at org.apache.spark.sql.catalyst.expressions.codegen.GenerateSafeProjection$.create(GenerateSafeProjection.scala:194)
    at org.apache.spark.sql.catalyst.expressions.codegen.GenerateSafeProjection$.create(GenerateSafeProjection.scala:36)
    at org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator.generate(CodeGenerator.scala:930)
    at org.apache.spark.sql.Dataset.org$apache$spark$sql$Dataset$$collectFromPlan(Dataset.scala:2860)
    at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2150)
    at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2150)
    at org.apache.spark.sql.Dataset$$anonfun$55.apply(Dataset.scala:2842)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:65)
    at org.apache.spark.sql.Dataset.withAction(Dataset.scala:2841)
    at org.apache.spark.sql.Dataset.head(Dataset.scala:2150)
    at org.apache.spark.sql.Dataset.take(Dataset.scala:2363)
    at org.apache.spark.sql.Dataset.showString(Dataset.scala:241)
    at org.apache.spark.sql.Dataset.show(Dataset.scala:637)
    at org.apache.spark.sql.Dataset.show(Dataset.scala:596)
    at org.apache.spark.sql.Dataset.show(Dataset.scala:605)
    at Demo$.main(Demo.scala:15)

的pom.xml

`

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Demo</groupId>
  <artifactId>Demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>Demo</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-core_2.11</artifactId>
    <version>2.2.1</version>
</dependency>
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-sql_2.11</artifactId>
    <version>2.2.1</version>
</dependency>
  </dependencies>
</project> 

`

1 个答案:

答案 0 :(得分:0)

我已经找到解决此问题的方法。

解决方案:在Scala IDE中转到:

  

帮助-> 安装新软件-> 未选中   安装以找到所需的软件

下面附上了屏幕截图。

enter image description here