Java spark在EMR上提交JAR时发生ClassNotFoundException
我正在使用eclipse/Maven创建一个JAR,并在EMR上运行它 这是我的pom.xml文件Java spark在EMR上提交JAR时发生ClassNotFoundException,java,scala,hadoop,apache-spark,amazon-emr,Java,Scala,Hadoop,Apache Spark,Amazon Emr,我正在使用eclipse/Maven创建一个JAR,并在EMR上运行它 这是我的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-
<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>com.sudarshan</groupId>
<artifactId>SparkApplication</artifactId>
<version>SQL</version>
<packaging>jar</packaging>
<name>SparkApplication</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Maven Assembly Plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>financialLineItem.FinancialLineItem</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase> <!-- packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
当我在齐柏林飞艇笔记本中运行代码时,它运行良好,但在spark submit
中,它抛出以下异常
Exception in thread "main" java.lang.ClassNotFoundException: financialLineItem.FinancialLineItem
我的项目设置如下所示:
如何纠正这一点
此外,我还按照以下文档创建spark并在EMR中提交
在这里,他们既没有在spark作业配置中设置主URL,也没有在spark提交时设置主URL,您的
pom.xml
中缺少sourceDirectory
根据,默认的sourceDirectory
是src/main/java
,由于您的项目结构是src/main/scala
,因此不会编译这些类
在生成配置下添加以下内容:
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<finalName>Sample</finalName>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.3</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-make:transitive</arg>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<useFile>false</useFile>
<disableXmlReport>true</disableXmlReport>
<!-- If you have classpath issue like NoDefClassError,... -->
<!-- useManifestOnlyJar>false</useManifestOnlyJar -->
<includes>
<include>**/*Test.*</include>
<include>**/*Suite.*</include>
</includes>
</configuration>
</plugin>
<!--
Maven Assembly Plugin
-->
</plugins>
</build>
src/main/scala
src/test/scala
样品
net.alchim31.maven
scala maven插件
3.1.3
编译
测试编译
-make:及物的
-从属文件
${project.build.directory}/.scala\u依赖项
org.apache.maven.plugins
maven surefire插件
2.13
假的
真的
**/*测试*
**/*套房*
在群集模式下运行spark submit时,会发生的情况是驱动程序运行在与客户端不同的机器上,因此您在spark submit脚本中提供的jar需要放置在驱动程序的类路径上,如下所示:-
--driver-class-path s3://path/SparkApplication-SQL-jar-with-dependencies.jar
因此,您可以按如下方式尝试以下脚本:
spark-submit --deploy-mode cluster --class financialLineItem.FinancialLineItem --driver-class-path s3://path/SparkApplication-SQL-jar-with-dependencies.jar
spark-submit --deploy-mode cluster --class financialLineItem.FinancialLineItem --driver-class-path s3://path/SparkApplication-SQL-jar-with-dependencies.jar