失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Spark一路火花带闪电——Spark踩坑记

Spark一路火花带闪电——Spark踩坑记

时间:2023-10-21 17:22:22

相关推荐

Spark一路火花带闪电——Spark踩坑记

文章目录

坑有哪些?踩坑记:版本号一定要正确!!!JDK一定要匹配。使用idea打包maven项目

坑有哪些?

ClassNotFoundException:表明maven依赖和服务器中的版本不匹配。Unsupported class file major version 55:表明jdk版本不适配spark(过高,出现minor则过低)数组越界IndexOutOfBoundsException:表明jdk版本不适合spark

踩坑记:版本号一定要正确!!!JDK一定要匹配。

我这里使用的是scala 2.11.12 和spark 2.4.1(不知道自己版本号的同学可以使用spark-shell,查看自己的版本号)

该版本号下,一定要使用jdk1.8,如果使用jdk1.7会出现低版本错误,使用jdk11或者jdk12会有高版本错误。

出现的错误如下:

Unsupported major.minor version 52.0 (低版本错误)

Unsupported class file major version 55 (高版本错误)

另外还会出现数组越界的错误。都是jdk版本不匹配的问题。

注意这里的jdk8对应的是scala 2.11.12 - spark 2.4.1

其他版本可能不通用。

使用idea打包maven项目

使用maven创建spark项目,如下图所示,然后点击下一步,输入groupId和artifactId即可创建完毕。

注意:这里project SDK一定要改成jdk8

创建完毕后,修改pom.xml

<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.leesangHyuk</groupId><artifactId>recommend</artifactId><version>1.0-SNAPSHOT</version><inceptionYear></inceptionYear><properties><scala.version>2.11.12</scala.version><spark.version>2.4.0</spark.version></properties><repositories><repository><id>scala-</id><name>Scala-Tools Maven2 Repository</name><url>http://scala-/repo-releases</url></repository></repositories><pluginRepositories><pluginRepository><id>scala-</id><name>Scala-Tools Maven2 Repository</name><url>http://scala-/repo-releases</url></pluginRepository></pluginRepositories><dependencies><dependency><groupId>org.apache.spark</groupId><artifactId>spark-core_2.11</artifactId><version>${spark.version}</version></dependency><dependency><groupId>org.apache.spark</groupId><artifactId>spark-mllib_2.11</artifactId><version>${spark.version}</version></dependency><dependency><groupId>org.apache.spark</groupId><artifactId>spark-sql_2.11</artifactId><version>${spark.version}</version></dependency><dependency><groupId>org.scala-lang</groupId><artifactId>scala-library</artifactId><version>${scala.version}</version></dependency></dependencies><build><sourceDirectory>src/main/scala</sourceDirectory><plugins><plugin><groupId>org.scala-tools</groupId><artifactId>maven-scala-plugin</artifactId><executions><execution><goals><goal>compile</goal><goal>testCompile</goal></goals></execution></executions><configuration><scalaVersion>${scala.version}</scalaVersion><args><arg>-target:jvm-1.5</arg></args></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-eclipse-plugin</artifactId><configuration><downloadSources>true</downloadSources><buildcommands><buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand></buildcommands><additionalProjectnatures><projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature></additionalProjectnatures><classpathContainers><classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer><classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer></classpathContainers></configuration></plugin></plugins></build><reporting><plugins><plugin><groupId>org.scala-tools</groupId><artifactId>maven-scala-plugin</artifactId><configuration><scalaVersion>${scala.version}</scalaVersion></configuration></plugin></plugins></reporting></project>

注意这里的maven的依赖一定要和服务器里的scala 和spark版本一致,否则会出现ClassNotFoundException错误。

然后在 project structure里,加入scala 2.11.12的jdk

加入完成后,在Artifacts里面,加入jar包。

初次创建的时候,一定要指明Main Class。之后创建的不需要。

然后把extracted xxx.jar 全部删掉,不删可能spark-submit的时候会报错。

删到这个程度即可。

然后应用。打包。

打包完成后,传到spark服务器。

运行./start-all.sh后,通过spark-submit提交任务。

spark-submit --class com.leesangHyuk.Recommend --master spark://slave:7077 recommend.jar

–class后面一定是包+类名。

如果觉得《Spark一路火花带闪电——Spark踩坑记》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。