【问题标题】:Spark SBT compilation issueSpark SBT 编译问题
【发布时间】:2016-09-16 14:22:34
【问题描述】:

在我的编译中,即使我将 twitter jar 文件放在 src/main/resources 文件夹中,但 SBT 编译并没有拾取它们并编译和打包没有错误,但在运行时给我错误,因为“找不到类 twitterUtils "

我的问题是为什么 SBT 没有在编译中包含资源文件夹中的 jar 文件?

人们告诉我要执行所有这些复杂的步骤来获取 Git 实用程序,然后执行我所做的 sbt 程序集,但是由于代理 Git 的 iam 无法正常工作,即使所有的 http_proxy 设置。 我还尝试将这些 twitter jar 文件放在 CLASSPATH 中,但没有成功。 我被这个问题困住了,所以非常感谢任何帮助。 请看下面的详细信息

[root@hadoop1 TwitterPopularTags]# pwd
/root/TwitterPopularTags
[root@hadoop1 TwitterPopularTags]# sbt compile
[info] Set current project to TwitterPopularTags (in build file:/root/TwitterPopularTags/)
[info] Updating {file:/root/TwitterPopularTags/}twitterpopulartags...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 2 Scala sources to /root/TwitterPopularTags/target/scala-2.11/classes...
[success] Total time: 14 s, completed Sep 16, 2016 9:55:20 AM
[root@hadoop1 TwitterPopularTags]# sbt package
[info] Set current project to TwitterPopularTags (in build file:/root/TwitterPopularTags/)
[info] Packaging /root/TwitterPopularTags/target/scala-2.11/twitterpopulartags_2.11-1.0.jar ...
[info] Done packaging.
[success] Total time: 1 s, completed Sep 16, 2016 9:56:20 AM
[root@hadoop1 TwitterPopularTags]# spark-submit /root/TwitterPopularTags/target/scala-2.11/twitterpopulartags_2.11-1.0.jar
16/09/16 09:57:06 INFO SparkContext: Running Spark version 1.6.2
16/09/16 09:57:06 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
16/09/16 09:57:06 INFO SecurityManager: Changing view acls to: root
16/09/16 09:57:06 INFO SecurityManager: Changing modify acls to: root
16/09/16 09:57:06 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users with view permissions: Set(root); users with modify permissions: Set(root)
16/09/16 09:57:07 INFO Utils: Successfully started service 'sparkDriver' on port 53967.
16/09/16 09:57:07 INFO Slf4jLogger: Slf4jLogger started
16/09/16 09:57:07 INFO Remoting: Starting remoting
16/09/16 09:57:07 INFO Remoting: Remoting started; listening on addresses :[akka.tcp://sparkDriverActorSystem@10.100.44.17:57877]
16/09/16 09:57:07 INFO Utils: Successfully started service 'sparkDriverActorSystem' on port 57877.
16/09/16 09:57:07 INFO SparkEnv: Registering MapOutputTracker
16/09/16 09:57:07 INFO SparkEnv: Registering BlockManagerMaster
16/09/16 09:57:07 INFO DiskBlockManager: Created local directory at /tmp/blockmgr-47a89077-0926-447c-ada7-fdb4a9aa1b83
16/09/16 09:57:07 INFO MemoryStore: MemoryStore started with capacity 511.5 MB
16/09/16 09:57:07 INFO SparkEnv: Registering OutputCommitCoordinator
16/09/16 09:57:08 INFO Server: jetty-8.y.z-SNAPSHOT
16/09/16 09:57:08 INFO AbstractConnector: Started SelectChannelConnector@0.0.0.0:4040
16/09/16 09:57:08 INFO Utils: Successfully started service 'SparkUI' on port 4040.
16/09/16 09:57:08 INFO SparkUI: Bound SparkUI to 0.0.0.0, and started at http://10.100.44.17:4040
16/09/16 09:57:08 INFO HttpFileServer: HTTP File server directory is /tmp/spark-d56628b6-fdbf-4d89-bbd2-a96603000607/httpd-ee499eb3-00ae-4276-b163-423e3b81f0b4
16/09/16 09:57:08 INFO HttpServer: Starting HTTP Server
16/09/16 09:57:08 INFO Server: jetty-8.y.z-SNAPSHOT
16/09/16 09:57:08 INFO AbstractConnector: Started SocketConnector@0.0.0.0:56067
16/09/16 09:57:08 INFO Utils: Successfully started service 'HTTP file server' on port 56067.
16/09/16 09:57:08 INFO SparkContext: Added JAR file:/root/TwitterPopularTags/target/scala-2.11/twitterpopulartags_2.11-1.0.jar at http://10.100.44.17:56067/jars/twitterpopulartags_2.11-1.0.jar with timestamp 1474034228091
16/09/16 09:57:08 INFO Executor: Starting executor ID driver on host localhost
16/09/16 09:57:08 INFO Utils: Successfully started service 'org.apache.spark.network.netty.NettyBlockTransferService' on port 49715.
16/09/16 09:57:08 INFO NettyBlockTransferService: Server created on 49715
16/09/16 09:57:08 INFO BlockManagerMaster: Trying to register BlockManager
16/09/16 09:57:08 INFO BlockManagerMasterEndpoint: Registering block manager localhost:49715 with 511.5 MB RAM, BlockManagerId(driver, localhost, 49715)
16/09/16 09:57:08 INFO BlockManagerMaster: Registered BlockManager
16/09/16 09:57:08 WARN DomainSocketFactory: The short-circuit local reads feature cannot be used because libhadoop cannot be loaded.
16/09/16 09:57:08 INFO EventLoggingListener: Logging events to hdfs:///spark-history/local-1474034228122
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/streaming/twitter/TwitterUtils$
        at dot.state.fl.us.PrintTweets$.main(PrintTweets.scala:29)
        at dot.state.fl.us.PrintTweets.main(PrintTweets.scala)

【问题讨论】:

    标签: apache-spark sbt


    【解决方案1】:

    我的问题是为什么 SBT 没有在编译中包含资源文件夹中的 jar 文件?

    因为这不是资源文件夹的用途。如果您想手动管理依赖项,put them into lib folder instead。但在这种情况下,您还需要对这些依赖项的所有依赖项、它们的依赖项等执行相同操作。如链接文档中所述,使用托管依赖项通常是一个更好的主意。

    【讨论】:

    • 嗨,Alexey,我没有看到链接的文档,您可以在这里发布链接吗?为什么 SBT 不下载依赖于 twitter 的 jar 文件,因为它在 build.sbt 文件“spark-streaming-twitter 的依赖项列表中?请参见下面的”libraryDependencies ++= Seq(“org.apache.spark”%% "spark-core" % sparkVersion, "org.apache.spark" %% "spark-streaming" % sparkVersion, "org.apache.spark" %% "spark-streaming-twitter" % sparkVersion ) "
    • 对不起,我发现链接没关系,但我的问题仍然存在。为什么即使它们在依赖项列表中,也没有下载 twitter jar?或者它们正在被下载,而我的类未找到错误是别的什么?
    • 我将我的 twitter jar 文件放在 lib 文件夹和 clean-compile-package 中,但仍然在找不到“twitterUtils”[root@hadoop1 lib]# pwd /root/TwitterPopularTags/lib [root @hadoop1 lib]# ls -ltr total 360 -rw-r--r-- 1 个根 60808 Sep 16 11:18 twitter4j-stream-4.0.4.jar -rw-r--r-- 1 个根 290456 9 月 16 日 11:18 twitter4j-core-4.0.4.ziptwitter4j-core-4.0.4.jar -rw-r--r-- 1 根 14115 9 月 16 日 11:18 dstream-twitter_2.11-0.1.0- SNAPSHOT.jar [root@hadoop1 lib]#
    • 我添加了 twitter4j 依赖项但仍然没有运气请帮助 libraryDependencies ++= Seq( "org.apache.spark" %% "spark-core" % sparkVersion, "org.apache.spark" % % "spark-streaming" % sparkVersion, "org.apache.spark" %% "spark-streaming-twitter" % sparkVersion, "org.twitter4j" % "twitter4j-core" % "3.0.3", "org.twitter4j " % "twitter4j-stream" % "3.0.3" ) 解析器 ++= Seq( "Akka Repository" at "repo.akka.io/releases" )
    猜你喜欢
    • 2016-12-30
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 2023-03-22
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多