2

I generated a jar using sbt assembly but when I am trying to run the jar I am getting the below error. I am using scala 2.12.0, sbt 0.13.8 and assembly 0.14.2. Can anyone help me out what this error means and the resolution?

Error: java.lang.ClassFormatError: Extra bytes at the end of class file
Ramesh Maharjan
  • 41,071
  • 6
  • 69
  • 97
ArunavaS
  • 197
  • 1
  • 12
  • Maybe related https://stackoverflow.com/questions/3045422/java-lang-classformaterror-extra-bytes-at-end-of-class-file – Matthew Farwell May 30 '17 at 12:11
  • 2
    solved using below lines in build.sbt `assemblyMergeStrategy in assembly := { case PathList("META-INF", xs @ _*) => MergeStrategy.discard case "reference.conf" => MergeStrategy.concat case x => MergeStrategy.first }` – ArunavaS May 30 '17 at 13:57
  • 2
    Can you answer you post yourself and accept the answer so that others can benefit from it too – Ramesh Maharjan May 30 '17 at 15:28
  • How would I answer my question? I cannot find any option to post ans – ArunavaS May 30 '17 at 17:36
  • @ArunavaS, there is a big text area with title "**Your Answer**" in the bottom of the page and a blue "**Post Your Answer**" button just under it. Your reputation should be enough to post an answer to your own question. – SergGr May 31 '17 at 23:28

1 Answers1

1

The OP posted a viable solution in the comments, but never made it into an actual answer. Since I encountered the same problem today and his comment solved it, I'll post this solution as an answer below.

-- answer from the OP, originally posted in the comments --

Solved using below lines in build.sbt

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

I'll just add that in my case, the critical addition was the middle case "reference.conf" which must trigger a concat merge strategy.

Jivan
  • 21,522
  • 15
  • 80
  • 131