1
votes

I am creating a JAR using eclipse/Maven and running it on EMR

Here is my pom.xml file

<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>

This is how I deploy and run my jar in EMR cluster

spark-submit --deploy-mode cluster --class financialLineItem.FinancialLineItem s3://path/SparkApplication-SQL-jar-with-dependencies.jar

When i run my code in zeppelin note book it runs fine, but in spark-submit it throws the below exception

Exception in thread "main" java.lang.ClassNotFoundException: financialLineItem.FinancialLineItem

This is how my project set-up looks like: enter image description here

How to correct this?

Also i have followed below document to create spark and submit in EMR https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-spark-submit-step.html Here they are neither setting master URL in the spark job configuration or while submitting from the spark-submit

2

2 Answers

1
votes

You are missing sourceDirectory in your pom.xml.

According to the Maven docs for Standard Directory Layout, the default sourceDirectory is src/main/java and since your Project structure is src/main/scala, the classes are not getting compiled.

Add this under your build configuration:

<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>
0
votes

When you run spark-submit in the cluster mode, what happens is the driver runs on a different machine than the client, so the jar which you have provided in the spark-submit script needs to be placed on the driver's class path like this:-

--driver-class-path s3://path/SparkApplication-SQL-jar-with-dependencies.jar

so you can try the below script as follows:

spark-submit --deploy-mode cluster --class financialLineItem.FinancialLineItem --driver-class-path s3://path/SparkApplication-SQL-jar-with-dependencies.jar