1

Here is the attempt to exclude the javax.servlet classes:

libraryDependencies ++= Seq(
 ..
  ("org.apache.spark" % "spark-core_2.10" % sparkVersion  \
  % "compile->default"  withSources()).exclude("org.mortbay.jetty", "servlet-api"),

Here is my attempt at a MergeStrategy:

mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) => {
 ..
    case PathList("javax", "servlet", xs @ _*)         => MergeStrategy.singleOrError
   ..

Following shows that multiple copies of the javax.servlet classes are being loaded:

[error] (*:assembly) singleOrError: found multiple files for same target path: [error] C:\Users\s80035683.ivy2\cache\org.mortbay.jetty\servlet-api-2.5\jars\servlet-api-2.5-6.1.14.jar:javax/servlet/Filter.class [error] C:\Users\s80035683.ivy2\cache\javax.servlet\servlet-api\jars\servlet-api-2.5.jar:javax/servlet/Filter.class [error] C:\Users\s80035683.ivy2\cache\org.eclipse.jetty.orbit\javax.servlet\orbits\javax.servlet-3.0.0.v201112011016.jar:javax/servlet/Filter.class [error] C:\Users\s80035683.ivy2\cache\org.mortbay.jetty\servlet-api\jars\servlet-api-2.5-20110124.jar:javax/servlet/Filter.class

Note: this is not a DUPLICATE since similar questions do NOT address this issue. For example +the answer to the following question ("highest version selected by default") is NOT working

How could SBT choose highest version amongst dependencies?

Community
  • 1
  • 1
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
  • 1
    You can use [sbt-dependency-graph](https://github.com/jrudolph/sbt-dependency-graph) and see from where the `servlet-api` is included. You can do that by using `what-depends-on `. Then you can exclude the transitive dependency. This is easier than excluding class from a specific jar (unless you don't care which jar, and you just want to take it from any jar). You can also check my answer to [another question](http://stackoverflow.com/questions/24363363/how-can-a-duplicate-class-be-excluded-from-sbt-assembly/24363781#24363781) – lpiepiora Jun 26 '14 at 06:38
  • thx! I will try this and likely follow-up with suggesting you make this an answer – WestCoastProjects Jun 26 '14 at 06:52

1 Answers1

1

You can use sbt-dependency-graph and see from where the servlet-api is included as a transitive dependency.

You can do that by using what-depends-on <organization> <module> <revision> command.

Knowing that you can exclude the transitive dependency.

This is easier than excluding class from a specific jar (unless you don't care which jar, and you just want to take it from any jar).

You can also check my answer to another question on how to write a custom MergeStrategy, which would know from which jar the class was comming.

Community
  • 1
  • 1
lpiepiora
  • 13,659
  • 1
  • 35
  • 47