J  Calbreath
J Calbreath

Reputation: 2705

SBT: Class not included in jar file

I am building an application and trying to package it as a fat jar via sbt assembly, but my class is not being included in the final jar file. It includes as dependencies two additional jar files that I have created. My code looks something like this:

package com.my.new.pacakge

import com.my.package.num1
import com.my.package.num2

object myNewObject { ....}

My build file looks like this:

organization := "com.my.new.package"

name := "myProject"

spName := "com.my.new.package/myNewObject"

version := "0.2"

scalaVersion := "2.10.4"

sparkVersion := "1.3.0"

sparkComponents ++= Seq("streaming", "sql")

libraryDependencies += "com.databricks" %% "spark-avro" % "1.0.0"

libraryDependencies += "org.apache.avro" % "avro" % "1.7.7"

libraryDependencies += "org.apache.avro" % "avro-mapred" % "1.7.7"

libraryDependencies += "com.my.package" % "num1" % "0.1"

libraryDependencies += "com.my.package" % "num2" % "0.2"

mergeStrategy in assembly := {case PathList("META-INF", xs @ _*) => MergeStrategy.discard
                              case x => MergeStrategy.concat}

lazy val sbtAssemblySettings = Seq(
    assemblyJarName in assembly := {name.value + "-" + version.value + ".jar"}, 
    mainClass in assembly := Some("com.my.new.package.myNewObject")
)

When I run assembly, the jar pacakges just fine, but if I run 'jar tf' to see what is in the jar, nothing related to com.my.new.package is there. Everything else seems to be there.

There are some common dependencies between my other jars and this new object that create some conflicts, hence the merge strategy. I suspect something in the merge strategy is causing myNewObject to be ejected but I'm not really sure why. If anyone can point out what I'm doing wrong it's greatly appreciated.

Upvotes: 1

Views: 1377

Answers (1)

0__
0__

Reputation: 67280

case x => MergeStrategy.concat

I think that means all your files except META-INF are jammed together in one. You will probably want to use the default strategy for anything that doesn't match your filter. From the README:

assemblyMergeStrategy in assembly := {
  case PathList("META-INF", xs @ _*) => MergeStrategy.discard
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}

Upvotes: 2

Related Questions