1.首先在 project/plugins.sbt: 下加入這段代碼:app
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
2.先對project 執行sbt 看看能不能經過 記住要在機子上裝好Git
3.在根目錄建立assembly.sbt文件,內容以下:this
import AssemblyKeys._ // put this at the top of the file assemblySettings // your assembly settings here
以後就能夠sbt assembly
來打包了,生成./target/scala_x.x.x/projectname-assembly-x.x.x.jar
4.若是想更詳細的配置assembly,能夠這樣spa
在assembly.sbt內寫入:scala
import AssemblyKeys._ assemblySettings jarName in assembly := "spark_sbt.jar" test in assembly := {} mainClass in assembly := Some( "Spark_Test") assemblyOption in packageDependency ~= { _.copy(appendContentHash = true) } mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) => { case PathList(ps @ _*) if ps.last endsWith "axiom.xml" => MergeStrategy.filterDistinctLines case PathList(ps @ _*) if ps.last endsWith "Log.class" => MergeStrategy.first case PathList(ps @ _*) if ps.last endsWith "LogConfigurationException.class" => MergeStrategy.first case PathList(ps @ _*) if ps.last endsWith "LogFactory.class" => MergeStrategy.first case PathList(ps @ _*) if ps.last endsWith "SimpleLog$1.class" => MergeStrategy.first case x => old(x) } }