I’m using a library called scalaplot, and I get the following java error. I’m wondering whether this is a bug in the scalaplot library, or an error in my own code.
Does this error seem to be an error in my code/installation or a buggy library? I get the same error even when I copy/paste the example on the webpage: https://github.com/sameersingh/scalaplot
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Product$class
Caused by: java.lang.ClassNotFoundException: scala.Product$class
... 5 more
Perhaps the library is no longer maintained? Nobody has responded to any of the documentation related issues that I’ve filed.
Is there a better way to make png or pdf plots than to use scalaplot? Of course I could write my own interface to gnuplot for the purpose I need. Would be nice to avoid that.
The last commit is from 4 years ago, so probably yes.
NoClassDefFound in the standard library namespace (it doesn’t find
scala.Product) is most likely caused by the library being compiled against an older Scala version than you use in your project. This library also uses the single
% for its sbt dependency in the doc, meaning it doesn’t have different artifacts on maven for different scala versions. The POM in the repo is using Scala 2.11, so it’s not compatible with Scala 2.12.
You could try to compile the library against 2.12, but your best bet is probably to look for a more current plotting library.
Thanks for the comment. If I have the file
sbt__org_sameersingh_scalaplot_scalaplot_0_0_4_jar.xml in my
.idea/libraries directory, does that mean it downloaded that file explicitly from the repo or does it mean that I downloaded the source and compiled it?
Not sure, but sbt doesn’t automatically build dependencies from source. It just assumes, that the scala version is irrelevant, if a single
% is used (usually that should only be the case for Java libraries).
To compile it from source, you’d usually clone the repo, change the scala version in the POM.xml and then use
mvn install (after which it should be in the local maven cache and be used by other projects when resolving dependencies, maybe increase the version too to prevent other caching).
I tried it just now, but stumbled upon compiler errors caused by
javax.swing no longer being in the default module in Java 11, and I have no experience with the new module system, so not sure what to do about it. It’s possible that it works with Java 8.
That’s very likely a problem with the library, as the library seems not properly published with a scala version suffix.
The NoClassDefFoundError is thrown because the library uses Scala 2.11 and you are using Scala 2.12 which are not binary compatible.
Thanks. I’ve sent an email to the author. Looks like he’s still active on other projects, just hasn’t touched this one in a while. Let’s see if he responds to my email.