首页 > 其他分享 >安装spark local运行出现错误NoClassDefFoundError: org/slf4j/Logger 原来是要设置

安装spark local运行出现错误NoClassDefFoundError: org/slf4j/Logger 原来是要设置

时间:2023-07-28 23:09:06浏览次数:56  
标签:opt java NoClassDefFoundError hadoop HADOOP slf4j HOME org spark

Error: Unable to initialize main class org.apache.spark.deploy.SparkSubmit Caused by: java.lang.NoClassDefFoundError: org/slf4j/Logger

 

How to install spark locally

Considering spark without hadoop built-in.

  • Download hadoop unpack to /opt/hadoop/
  • Download spark without hadoop, unpack to /opt/spark
  • Install java. Set JAVA_HOVE environment variable. For example: export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
  • create environment variables required for spark to run. One can put those in .bashrc
export HADOOP_HOME=/opt/hadoop
export SPARK_DIST_CLASSPATH=$HADOOP_HOME/etc/hadoop/*:$HADOOP_HOME/share/hadoop/common/lib/*:$HADOOP_HOME/share/hadoop/common/*:$HADOOP_HOME/share/hadoop/hdfs/*:$HADOOP_HOME/share/hadoop/hdfs/lib/*:$HADOOP_HOME/share/hadoop/hdfs/*:$HADOOP_HOME/share/hadoop/yarn/lib/*:$HADOOP_HOME/share/hadoop/yarn/*:$HADOOP_HOME/share/hadoop/mapreduce/lib/*:$HADOOP_HOME/share/hadoop/mapreduce/*:$HADOOP_HOME/share/hadoop/tools/lib/*

Now you can run pyspark for example:

$ /opt/spark/bin/pyspark 
Python 2.7.12 (default, Nov 12 2018, 14:36:49) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/spark/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
2019-01-31 08:36:02 WARN  Utils:66 - ....
2019-01-31 08:36:02 WARN  Utils:66 - Set SPARK_LOCAL_IP if you need to bind to another address
2019-01-31 08:36:03 WARN  NativeCodeLoader:60 - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
2019-01-31 08:36:04 WARN  Utils:66 - Service 'SparkUI' could not bind on port 4040. Attempting port 4041.
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /__ / .__/\_,_/_/ /_/\_\   version 2.3.2
      /_/

Using Python version 2.7.12 (default, Nov 12 2018 14:36:49)
SparkSession available as 'spark'.
>>> exit()

Running pyspark in jupyter notebooks locally

To open interactive pyspark session in jupyter notebooks do this:

export PYSPARK_DRIVER_PYTHON=jupyter
export PYSPARK_DRIVER_PYTHON_OPTS='notebook'
/opt/spark/bin/pyspark

Here jupyter server running locally connects to the spark running locally.

Troubleshooting

if you get

/opt/spark/bin$ ./pyspark
Python 2.7.12 (default, Nov 12 2018, 14:36:49) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/Logger
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.slf4j.Logger
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 7 more
Traceback (most recent call last):
  File "/opt/spark/python/pyspark/shell.py", line 38, in <module>
    SparkContext._ensure_initialized()
  File "/opt/spark/python/pyspark/context.py", line 300, in _ensure_initialized
    SparkContext._gateway = gateway or launch_gateway(conf)
  File "/opt/spark/python/pyspark/java_gateway.py", line 93, in launch_gateway
    raise Exception("Java gateway process exited before sending its port number")
Exception: Java gateway process exited before sending its port number

that means that you haven’t set SPARK_DIST_CLASSPATH (spark cannot find slf4j which is needed for logging)

See also

标签:opt,java,NoClassDefFoundError,hadoop,HADOOP,slf4j,HOME,org,spark
From: https://blog.51cto.com/u_11908275/6887974

相关文章

  • 我的世界(MC) forge 1.19.3 开服教程
    Debian系统使用MCSManager9面板搭建MinecraftJava版MOD服务器的教程,本教程用的forge1.19.3服务端,用其他服务端的也可以参考一下。其他版本我的世界服务器搭建教程:https://blog.zeruns.tech/tag/mc/各种Minecraft服务端介绍和下载:https://blog.zeruns.tech/archives/626.html高性价......
  • 云图说丨初识华为云OrgID:轻松实现统一帐号、统一授权
    本文分享自华为云社区《【云图说】第282期初识华为云OrgID:轻松实现统一帐号、统一授权》,作者:阅识风云。组织成员帐号OrgID是面向企业提供组织管理、企业成员帐号管理以及SaaS应用授权管理能力的云服务。OrgID将HuaweiID帐号体系延伸到企业用户,统一华为云面向生态SaaS服务的组......
  • org.springframework.beans.factory.parsing.BeanDefinitionParsingException
    org.springframework.beans.factory.parsing.BeanDefinitionParsingException:Configurationproblem:Failedtoimportbeandefinitionsfromrelativelocation[spring-controller.xml]Offendingresource:classpathresource[applicationContext.xml];nestedexcep......
  • Android studio id 'org.jetbrains.kotlin.android' version '1.7.20' apply fals
    如何实现"Androidstudioid'org.jetbrains.kotlin.android'version'1.7.20'applyfalse"在Android开发中,AndroidStudio是一个常用的集成开发环境(IDE),用于开发Android应用程序。在AndroidStudio中,我们可以使用Kotlin作为一种更现代化的编程语言。本文将向刚入行的开发者介绍......
  • VS 还原 NuGet 程序包时出错: 无法加载源 https://dotnet.myget.org/F/aspnetcore-dev
    错误还原NuGet程序包时出错:无法加载源https://dotnet.myget.org/F/aspnetcore-dev/api/v3解决方法在新源中添加地址:https://www.nuget.org/api/v2/......
  • n stable报错curl: (7) Failed to connect to nodejs.org port 443: Connection refus
    nstable报错curl:(7)Failedtoconnecttonodejs.orgport443:ConnectionrefusedError:failedtodownloadversionindex(https://nodejs.org/dist/index.tab)使用淘宝源exportN_NODE_MIRROR=https://npm.taobao.org/mirrors/nodenstable......
  • kettle连接数据库报错:Error connecting to database: (using class org.gjt.mm.mysql.
    kettle连接MySQL报错但已经把相应的包放到kettle的lib目录下时,仍然报连接不上的错误,那可能是MySQL时区的问题。解决如下:登入MySQL修改为东八区的命令:方法一:mysql>setglobalmax_allowed_packet=1024*1024;mysql>setglobaltime_zone='+8:00';方法二:修改my.ini文件,在[mysql......
  • 【JAVA】java日志框架 - slf4j
    1、配置依赖<!--slf4j日志门面--><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.26</version></dependenc......
  • Spring Boot 使用 slf4j 日志
    logback的使用     在学习JAVA闲暇时间翻阅别人的随笔中的过程中,我发现在学习开发中我们经常使用System.out.println()来打印一些信息用来输出日志,但是这样不好,因为这样会在大量的使用System.out的过程中会增加资源的消耗,在查阅相关资料后我发现在实际项目中我们可以使......
  • 2022 javax.management.InstanceNotFoundException: org.springframework.boot:ty
    解决"2022javax.management.InstanceNotFoundException:org.springframework.boot:ty"的步骤对于这个错误,我们需要明确以下几个步骤来解决问题。下面是一个整体的流程表格:步骤描述1确认是否存在相关的InstanceNotFoundException异常2检查org.springframework.boo......