1

I downloaded Typesafe's Scala IDE bundle, and now I try to make it work with my project, which uses Scala 2.9.2 and Java 7. My problem is, Eclipse still compiles it with Java 6, and I get those nasty errors about javax.swing.JComboBox does not take type parametes.

I'm launching eclipse with JAVA_HOME pointing to my jdk7/jre directory, and I added JRE 7 libs to the project. What am I doing wrong?

EDIT: For some reason, it seems that only Scala compiler compiles with Java 6 - if I use plain .java file, it seems to be compiled with proper version. How could it be that Eclipse uses two different jdk's in one project?

Rogach
  • 26,050
  • 21
  • 93
  • 172
  • Incredibly, there's no way to tell sbt which version of the Java libraries you need to compile your project against. See this question: http://stackoverflow.com/questions/7701692/how-do-i-configure-sbt-to-use-java-7. I asked again recently about this on the sbt mailing list and no-one replied, so presumably no change. – Luigi Plinge Oct 23 '12 at 05:57
  • @LuigiPlinge - Well, that's exactly what I do when I work with sbt. But now I use Eclipse, and it starts sbt behind the scenes? Is there a way to influence which jre Eclipse uses when starting sbt? – Rogach Oct 23 '12 at 06:02
  • 1
    It doesn't use sbt to compile, it uses some of the libraries to work out what to compile. Scala-ide uses the presentation compiler to compile. – Matthew Farwell Oct 23 '12 at 06:25
  • @MatthewFarwell - So why those libraries still use java 6? Even if eclipse is started with java 7? – Rogach Oct 23 '12 at 09:20
  • When you say 'the scala compiler compiles with java 6', do you mean that the class files generated aren't correct, or that the jars that you're using are incorrect, and still using the jdk 1.6 jars? IIRC correctly, the jars used are those in the project build path, so this should work. – Matthew Farwell Oct 23 '12 at 10:13
  • In your project's properties, what is defined under Java Build Path and Java Compiler? – Brian Smith Oct 23 '12 at 12:16
  • @MatthewFarwell - I'm using the correct jars, but it still complains that `javax.swing.JComboBox does not take type parametes`. Which indicates that it is using java 6, because those type parameters were added in Java 7. – Rogach Oct 24 '12 at 09:13
  • @BrianSmith - In java build path - Scala-2.9.3-**, JavaSE-1.7. In Java Compiler - "Use compliance from execution environment 'JavaSE-1.7' on build path". – Rogach Oct 24 '12 at 09:16

1 Answers1

1

The eclipse IDE is launched with whatever is the default JRE for your environment, like the one specified with the JAVA_HOME.

In this it's just like any other java application on your machine.

The jdk used to compile and run code within the ide is totally independent and it's defined within eclipse preferences under

Java > Installed JREs

You can add any runtime or sdk there and choose the default one used for new projects.

Additionally you can override this preference for each project within the project properties

In this way the compilation output is independent from your machine java environment, and can optionally be defined on a per-project basis.

As for the Scala-IDE, I need time because I don't have it installated on my day-job machine. I'll check later.

pagoda_5b
  • 7,333
  • 1
  • 27
  • 40
  • The problem is exactly that - I've already modified JAVA_HOME and friends, and plain Java code is compiled with Java 7. The only problem is scala code, that still seems to use old jdk. – Rogach Oct 24 '12 at 09:12
  • On the release notes of [Scala IDE for Eclipse 2.0.2 RC1)() there's a note saying: **Better support for JDK 7** - The Scala presentation compiler used to (incorrectly) use the running JDK, instead of the one configured on the build path. Now it will honor the correct JDK, meaning that Eclipse can run on JDK 6, but your project can compile against JDK 7. – pagoda_5b Oct 24 '12 at 15:28
  • Can't say if that's related to your problem since you updated the JVM running eclipse. What Scala IDE version are you using? – pagoda_5b Oct 24 '12 at 15:30
  • "About" page says `2.1-M2-20120914-Typesafe`. – Rogach Oct 24 '12 at 16:12
  • Sorry, I can't seem to find anything about this in the mailing list, maybe you should ask for help [there](https://groups.google.com/forum/#!forum/scala-ide-user) – pagoda_5b Oct 25 '12 at 15:01