【发布时间】:2018-01-29 01:16:18
【问题描述】:
我使用 maven 来管理我的项目。 我确实添加了
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql-kafka-0-10_2.11</artifactId>
<version>2.2.0</version>
到maven依赖
下面是我的 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-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>***</groupId>
<artifactId>***</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.11</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>2.11.8</scalaVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<groupId>org.apache.maven.plugins</groupId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>***</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql-kafka-0-10_2.11</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka-0-10_2.11</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.scalaj</groupId>
<artifactId>scalaj-http_2.11</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
</project>
我使用以下方法打包所有内容:
mvn clean package
我通过键入以下内容在本地提交我的工作:
spark-submit --class ... <path to jar file> <arguments to run the main class>
但我会收到一条错误消息:线程“main”java.lang.ClassNotFoundException中的异常:找不到数据源:kafka。请在http://spark.apache.org/third-party-projects.html查找包
我知道我可以通过在 spark-submit 后添加 --packages org.apache.spark:spark-sql-kafka-0-10_2.11:2.2.0 来解决此问题。
但是我怎样才能修改我的 pom 以避免这样做呢? 东西在我的 maven repo 中,我可以看到 spark-sql-kafka-0-10_2.11-2.2.0.jar 已经下载。那为什么我需要在 spark 提交期间手动添加依赖项? 我觉得我的 pom.xml 中可能有一些错误,即使我使用程序集来构建我的 jar。
希望有人能帮帮我!
【问题讨论】:
-
您是否尝试过查看 uber JAR 以查看是否附加了 sql-kafka jar?另外,我会在这里回答:stackoverflow.com/questions/39132906/…
标签: maven apache-kafka spark-streaming