Compiling Spark Scala Program into jar file using installed spark and maven
仍在尝试熟悉 maven 并将我的源代码编译成 jar 文件用于 spark-submit。我知道如何为此使用 IntelliJ,但想了解这实际上是如何工作的。我有一个 EC2 服务器,已经安装了所有最新的软件,例如 spark 和 scala,并且有我现在想用 maven 编译的示例 SparkPi.scala 源代码。我的愚蠢问题首先是,我可以只使用我安装的软件来构建代码而不是从 maven 存储库中检索依赖项,以及如何从基本的 pom.xml 模板开始添加适当的需求。我不完全理解 maven 到底在做什么,我该如何测试我的源代码的编译?
据我了解,我只需要拥有标准目录结构
除了@Krishna,
如果您有
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <build><sourceDirectory>src</sourceDirectory> <plugins><plugin> maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> maven-assembly-plugin</artifactId> <version>2.4</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>assemble-all</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin></plugins> </build> |
更多详情:链接
如果您有
1 2 3 4 5 6 7 8 9 10 11 12 | assemblyJarName :="WordCountSimple.jar" // val meta ="""META.INF(.)*""".r assemblyMergeStrategy in assembly := { case PathList("javax","servlet", xs@_*) => MergeStrategy.first case PathList(ps@_*) if ps.last endsWith".html" => MergeStrategy.first case n if n.startsWith("reference.conf") => MergeStrategy.concat case n if n.endsWith(".conf") => MergeStrategy.concat case meta(_) => MergeStrategy.discard case x => MergeStrategy.first } |
也
1 | addSbtPlugin("com.eed3si9n" %"sbt-assembly" %"0.13.0") |
有关更多信息,请参阅此和此。
到这里为止,主要目标是在目标文件夹中获取具有所有依赖项的 fat-jar。使用该 jar 在集群中运行,如下所示:
1 | hastimal@nm:/usr/local/spark$ ./bin/spark-submit --class com.hastimal.wordcount --master yarn-cluster --num-executors 15 --executor-memory 52g --executor-cores 7 --driver-memory 52g --driver-cores 7 --conf spark.default.parallelism=105 --conf spark.driver.maxResultSize=4g --conf spark.network.timeout=300 --conf spark.yarn.executor.memoryOverhead=4608 --conf spark.yarn.driver.memoryOverhead=4608 --conf spark.akka.frameSize=1200 --conf spark.io.compression.codec=lz4 --conf spark.rdd.compress=true --conf spark.broadcast.compress=true --conf spark.shuffle.spill.compress=true --conf spark.shuffle.compress=true --conf spark.shuffle.manager=sort /users/hastimal/wordcount.jar inputRDF/data_all.txt /output |
这里我有
请按照以下步骤
1 2 3 4 5 6 7 8 9 10 11 | # create assembly jar upon code change sbt assembly # transfer the jar to a cluster scp target/scala-2.10/myproject-version-assembly.jar <some location in your cluster> # fire spark-submit on your cluster $SPARK_HOME/bin/spark-submit --class not.memorable.package.applicaiton.class --master yarn --num-executor 10 \\ --conf some.crazy.config=xyz --executor-memory=lotsG \\ myproject-version-assembly.jar \\ <glorious-application-arguments...> |