1

I am making an uber-jar (i.e. containing scala-runtime classes inside) using scala and maven (maven-shade-plugin). I need it to run with (using scala console) and without scala runtime libs on classpath (as a standalone jar). So I did the following:

  1. shaded classes to scala to scala_2_12_8 using maven-shade-plugin (i.e. scala runtime is places in scala_2_12_8 package)
  2. ran scala 2.12.8 console
  3. loaded my jar using require my.jar (my_2.12-2.1.3-SNAPSHOT.jar) When I try to create to create an object using new org.test.MyObject, I get the following exceptions:
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading package, class file '/home/cergey/Documents/my_2.12-2.1.3-SNAPSHOT.jar(scala_2_12_8/package.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading MyObject, class file '/home/cergey/Documents/my_2.12-2.1.3-SNAPSHOT.jar(org/test/MyObject.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
<console>:12: error: my.MyObject does not have a constructor
       new test.MyObject

Scala console version and version in the jar match. When I run without scala runtime classes, everything works fine. Could someone point in what's happening, i.e. why jvm is looking for Scala annotation on non-scala class ?

Cergey Chaulin
  • 241
  • 1
  • 2
  • 5

1 Answers1

0

After two hours of debugging, I arrived at the most obvious revelation: our shaded jar with a shaded scala library has a renamed package package of ScalaSignature(i.e. scala_2_11.reflect.ScalaSignature) but scala compiler (that was launched by spark) when parsing classes expects it to be scala.reflect.ScalaSignature. The solution is not bundle scala library with application. I also found this question on SO.

Cergey Chaulin
  • 241
  • 1
  • 2
  • 5