Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running spark inside intellij idea HttpServletResponse - ClassNotFoundException

I try to run Spark with Scala from inside Intellij Idea:

object SimpleApp {
  def main(args: Array[String]) {
    val logFile = "/home/kamil/Apps/spark-1.2.1-bin/README.md" // Should be some file on your system
    val conf = new SparkConf().setAppName("Simple Application").setMaster("local[4]")
    val sc = new SparkContext(conf)
    val logData = sc.textFile(logFile, 2).cache()
    val numAs = logData.filter(line => line.contains("a")).count()
    val numBs = logData.filter(line => line.contains("b")).count()
    println("Lines with a: %s, Lines with b: %s".format(numAs, numBs))
  }
}

Running it within spark-submit works all right. Running it from IDE result in a following error:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletResponse
    at org.apache.spark.HttpServer.org$apache$spark$HttpServer$$doStart(HttpServer.scala:74)
    at org.apache.spark.HttpServer$$anonfun$1.apply(HttpServer.scala:61)
    at org.apache.spark.HttpServer$$anonfun$1.apply(HttpServer.scala:61)
    at org.apache.spark.util.Utils$$anonfun$startServiceOnPort$1.apply$mcVI$sp(Utils.scala:1765)
    at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:141)
    at org.apache.spark.util.Utils$.startServiceOnPort(Utils.scala:1756)
    at org.apache.spark.HttpServer.start(HttpServer.scala:61)
    at org.apache.spark.HttpFileServer.initialize(HttpFileServer.scala:46)
    at org.apache.spark.SparkEnv$.create(SparkEnv.scala:320)
    at org.apache.spark.SparkEnv$.createDriverEnv(SparkEnv.scala:159)
    at org.apache.spark.SparkContext.<init>(SparkContext.scala:240)
    at SimpleApp$.main(SimpleApp.scala:8)
    at SimpleApp.main(SimpleApp.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletResponse
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 18 more

SimpleApp.scala:8 is the line with instantiating spark context. As someone suggested I've already added:

libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1"

but it didn't help. Do you have any ideas? Thanks in advance.

like image 657
iku Avatar asked Mar 17 '23 23:03

iku


1 Answers

I've just solved this issue myself. You need to change module settings.

Context Menu -> Open Module Settings -> Dependencies

Change the 'scope' of the missing jar from 'Provided' to 'Compile'.

like image 129
puppet Avatar answered Mar 19 '23 11:03

puppet