Reputation: 21635
I have to compile a Spark program which runs with Java 1.7. However, I have Java 1.8 installed on my computer. My code has both Scala and Java classes, and I compile using sbt. I know you that one can set target with javac, but since I compile using sbt, and therefore don't directly call javac, how can I compile such code for Java 1.7, with Java 1.8.
P.S: I don't want to separately install Java 1.7 on my computer.
Upvotes: 3
Views: 351
Reputation: 16086
Java is backward compatible, which means you can compile to Java 7 bytecode using Java 8 compiler
In sbt you must manually set target Java version:
javacOptions ++= Seq("-source", "1.7", "-target", "1.7"),
scalacOptions := Seq("-target:jvm-1.7")
It will tell javac and scalac to set Java 7 class headers
Upvotes: 4