简体   繁体   English

代码给出“线程“ main”中的异常” java.lang.NoClassDefFoundError”

[英]Code is giving “Exception in thread ”main“ java.lang.NoClassDefFoundError”

I have added following dependency. 我添加了以下依赖项。 When i change spark-streaming_2.12 to spark-streaming_2.11 it gives error this error 当我将spark-streaming_2.12更改为spark-streaming_2.11时,出现此错误

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/streaming/StreamingContext

Those are my dependencies: 这些是我的依赖项:

    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-streaming_2.12</artifactId>
      <version>2.4.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_2.11</artifactId>
      <version>2.4.0</version>
    </dependency>

My code: 我的代码:

def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setAppName("LogProcessor")
    // No need to create sparkContext as StreamingContext itself create one
    val streamer = new StreamingContext(conf,Seconds(20))
    val lines =  streamer.textFileStream("/home/ubuntu/Desktop/test/")
    println(lines)

  }

I think you may be running this in an environment that does not have the spark-streaming dependency available (and hence, it is not able to find the classes on it). 我认为您可能在没有可用的流火花依赖项的环境中运行此程序(因此,它无法在其上找到类)。

If that case, you may want to include the dependency in the jar itself. 在这种情况下,您可能需要将依赖项包含在jar本身中。 You may try removing the <scope>provided</scope> from the spark-streaming dependency definition. 您可以尝试从火花流依赖项定义中删除<scope>provided</scope>

Edit: To provide more info about why I think this is happening, probably your environment has spark-streaming_2.12 dependency in the classpath, but not the spark-streaming_2.11 one. 编辑:为了提供有关我认为这是为什么发生的原因的更多信息,可能您的环境在类路径中具有spark-streaming_2.12依赖项,但没有spark-streaming_2.11。 That is why I think you should include it in an uber jar (removing the provided part). 这就是为什么我认为您应该将其包括在超级罐子中(删除提供的部件)。 Alternatively, you could also include the dependency in your environment so that your process is able to find it. 另外,您也可以在您的环境中包括依赖项,以便您的进程能够找到它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“main”中的异常 java.lang.NoClassDefFoundError: scala/Cloneable - Exception in thread "main" java.lang.NoClassDefFoundError: scala/Cloneable 线程“main”中的异常 java.lang.NoClassDefFoundError: org/rogach/scallop/ScallopConf - Exception in thread "main" java.lang.NoClassDefFoundError: org/rogach/scallop/ScallopConf 线程“main”中的 Gatling 错误异常 java.lang.NoClassDefFoundError: io/gatling/charts/component/impl/ComponentLibraryImpl - Gatling Error Exception in thread "main" java.lang.NoClassDefFoundError: io/gatling/charts/component/impl/ComponentLibraryImpl 线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/spark/sql/Column - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/spark/sql/Column Scala:线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / log4j / LogManager - Scala : Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/log4j/LogManager 线程“主”中的scala EPFL异常java.lang.NoClassDefFoundError:javax / script / Compilable - scala EPFL Exception in thread “main” java.lang.NoClassDefFoundError: javax/script/Compilable 解决线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / hadoop / fs / FSDataInputStream - Solving Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStream 线程“main”中的 Apache Spark 异常 java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class - Apache Spark Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class 线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / spark / Logging - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/spark/Logging 线程“ main”中的异常java.lang.NoClassDefFoundError:com / twitter / chill / KryoBase - Exception in thread “main” java.lang.NoClassDefFoundError: com/twitter/chill/KryoBase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM