I'm trying to execute a scala code using scala 2.10.2, the code uses some jar libraries compiled with sbt.
I get the following error:
scala: error while loading Order, class file '..\prestashop-scala-client-0.2.4\target\prestasac-0.2.4.jar(co/orderly/prestasac/representations/Order.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
Sources of the prestasac-0.2.4.jar are on github: Order.class
Is there something to do to fix this issue ?
Thank you
Looks like the library is configured to compile against Scala 2.9.1. Major versions of Scala are not binary compatible.
I put the necessary SBT changes here: https://github.com/mpartel/prestashop-scala-client/commit/e9a1df40bfe35518aaebac899e438b9b6fa6d728
Related
The default version of Scala complier of Scala IDE for eclipse is 2.12. It runs well for hello world.
However when I change the Scala complier version to 2.11 like following:
Then it shows Error: Could not find or load main class
When I change back to 2.12, it works again.
My question:
My Scala IDE for eclipse version is latest. Why this happens? And what should I do? I have to change to scala 2.11 to load the apache-spark 2.4 jar files. Otherwise it will show errors.
I'm trying to follow the instructions in this guide http://lamp.epfl.ch/files/content/sites/lamp/files/teaching/progfun/ScalacheckTutorial.html
in order to use ScalaCheck in Scala IDE.
However, when I create the first file StringSpecification.scala, with this code:
package pp.scalacheck
import org.scalacheck._
import Prop.forAll
object StringSpecification extends Properties("String") {
property("startsWith") = forAll { (x: String, y: String) =>
(x + y).startsWith(x)
}
}
I get the following error in Scala IDE:
bad symbolic reference to scala.util.parsing encountered in class file
'CmdLineParser.class'. Cannot access term parsing in package
scala.util. The current classpath may be missing a definition for
scala.util.parsing, or CmdLineParser.class may have been compiled
against a version that's incompatible with the one found on the
current classpath. (NOTE: It looks like the scala-parser-combinators
module is missing; try adding a dependency on "org.scala-lang.modules"
: "scala-parser-combinators". See
http://docs.scala-lang.org/overviews/core/scala-2.11.html for more
information.)
Error in Scala compiler: bad symbolic reference to
scala.util.parsing.combinator encountered in class file
'CmdLineParser.class'. Cannot access term combinator in value
scala.util.parsing. The current classpath may be missing a definition
for scala.util.parsing.combinator, or CmdLineParser.class may have
been compiled against a version that's incompatible with the one found
on the current classpath. (NOTE: It looks like the
scala-parser-combinators module is missing; try adding a dependency on
"org.scala-lang.modules" : "scala-parser-combinators". See
http://docs.scala-lang.org/overviews/core/scala-2.11.html for more
information.)
SBT builder crashed while compiling. The error message is 'bad
symbolic reference to scala.util.parsing.combinator encountered in
class file 'CmdLineParser.class'. Cannot access term combinator in
value scala.util.parsing. The current classpath may be missing a
definition for scala.util.parsing.combinator, or CmdLineParser.class
may have been compiled against a version that's incompatible with the
one found on the current classpath. (NOTE: It looks like the
scala-parser-combinators module is missing; try adding a dependency on
"org.scala-lang.modules" : "scala-parser-combinators". See
http://docs.scala-lang.org/overviews/core/scala-2.11.html for more
information.)'. Check Error Log for details.
I'm using the latest stable version of Scla IDE (for Eclipse) (3.0.4), ScalaCheck (2.11-1.11.6) and Scala (2.11.2), and I'm running on Windows.
What could be causing this error?
When I added this jar to the project I was able to build the example files:
http://search.maven.org/#artifactdetails%7Corg.scala-lang.modules%7Cscala-parser-combinators_2.11%7C1.0.2%7Cbundle
I've created Java annotations (since I need run time retention) under $PROJECT/src/main/java and my scala codewhich uses these java annotations us under $PROJECT/src/main/scala. The Java annotation thus created also makes use of a Java ENUM as it's value.
If I compile the project then sbt doesn't seem to compile the Java annotations first and errors out on each usage of the enum in annotations. If I comment out all usages of the Java enum in annotations in scala code and do a compile, uncomment enum usage and compile again it all works fine.
How do I ensure that sbt compiles my java annotations and enum (i.e. $PROJECT/src/main/java) before attempting to compile scala code when doing a clean build?
EDIT: I have a bare bones build.sbt and am using sbt 0.11.2
Some good news: This is a known issue and has been resolved.
Some bad news: It's resolved in 2.10 and the fix may not be backported to 2.9.3 (quoting Paul Phillips in the issue thread):
I've tagged this for backporting, which is not a guarantee; I don't
have time to do it right now but I expect to in the near future.
Some good news: If you're stuck on pre-2.10 and your Java sources don't depend on your Scala sources, you can just add the following to your build.sbt and all is well:
compileOrder := CompileOrder.JavaThenScala
Some bad news: If you're stuck on pre-2.10 and your Java sources do depend on your Scala sources, I'm pretty sure you're out of luck, and the comment-compile-uncomment trick is probably your best bet.
I'll bet you're facing SI-2764. This has been fixed in Scala 2.10.
In the meantime, create a separate sub-project for your Java annotations, and depend on this from the project containing the Scala code.. Then the Scala compiler will only process the .class files, rather the .java files.
Is is possible to compile and execute scala code as a string at runtime either in Scala or in Java?
My idea is to build a DSL using Scala then let Java programmers use the DSL inside Java.
I heard that the class scala.tools.nsc.Interpreter can do something like that, but when I imported it inside my scala file, I got "object tools is not a member of package scala."
So could anybody give me a hint?
In 2.10.0 we expose Scala reflection API, which among everything else includes a runtime compilation facility. More details can be found here: Generating a class from string and instantiating it in Scala 2.10.
I recommend you twitter-util's Eval
For scala3 this can be now achieved with dotty:
https://index.scala-lang.org/lampepfl/dotty
https://github.com/lampepfl/dotty
https://dotty.epfl.ch/docs/internals/overall-structure.html
The sbt dependency is e.g. "org.scala-lang" %% "scala3-compiler" % "3.1.3"
When trying to import scala.Option in a javafx script, I get the following javafxc error:
cannot access scala.Option.$anonfun$orNull$1
bad class file: scala/Option$$anonfun$orNull$1.class(scala:Option$$anonfun$orNull$1.class)
undeclared type variable: A1
Please remove or make sure it appears in the correct subdirectory of the classpath.
import scala.Option;
I am using Scala 2.8.1, Javafxc 1.3.1_b101, JVM 1.6.0_21-b06, OS Ubuntu 10.10. The same code was working in Scala 2.7.7 .
Later edit:
The same error is reported in case I import scala.immutable.Seq/List/Traversable/Iterable . I have tried the imports in a default Netbeans 6.9.1 JavaFX project which has in the classpath only scala-library.jar.
It reminded me first of #4067, but this one looks quite different.
I would suggest that you try to reproduce the error with 2.8.1 or 2.9 trunk, maybe it is fixed?