Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable JDK 7 in Eclipse Indigo on Mountain Lion

I'm working on a Scala Project with Eclipse (Indigo SR2). Today I updated my machine to Mountain Lion because we need some functionality of JDK 7. Installing JDK 7 worked fine:

$ java -version
java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

In Eclipse I changed the following settings:

  • Java => Compiler => Installed JREs: Adding JDK1.7.0 with path /Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home
  • Java => Compiler => Installed JREs => Exucution Environment: Set JavaSE-1.7 to JDK1.7.0
  • Java => Compiler: Compliance Level: 1.7
  • Scala => Compiler: Target = jvm-1.7

Then I restarted Eclipse and tried to run a script. However, I always get the error:

value getPlatformMXBean is not a member of object java.lang.management.ManagementFactory

Said method is only available as of Java 1.7 and Eclipse does not seem to find it although command-clicking on it reveals the function in the class ManagementFactory. About Eclipse => Configuration shows that it is still using JDK 6 (java.runtime.version=1.6.0_37-b06-434-11M3909), but I need JDK 7.

So I tried the following (as also described on StackOverflow and other sites):

  • add -vm /Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home/bin/java to the eclipse.ini file (double checked the path, the proper location in the file according to the eclipse website, and also added the newline in between)
  • add the same to the Info.plist
  • $ /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse -vm /Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home/
  • Create a symbolic link from 1.6 to 1.7

But no luck, Eclipse keeps starting with only JDK-6. What is strange is that I can explicitly change the JRE in Run=>Run Configurations to JDK7 and it will run it that way. But I would not want to change that for every single runnable file.

Any further suggestions?


Thanks to the hint from EECOLOR, I was able to use the Scala plugin in Eclipse Juno, where the JDK7 runs just fine. However, now I run into what appears to be a dependency issue. The exception I get can be seen here: https://gist.github.com/anonymous/ac0f3a3655419e5149fa

Strangly, the file just starts fine when I run it from the command line with a simple java -cp JARFILE com.AND-SO-ON.file. For building the sources and getting the dependencies, we use SBT.

My Eclipse.ini looks as follows (default except for the Xmx):

-startup
../../../plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
../../../plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.200.v20120522-1813
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Dhelp.lucene.tokenizer=standard
-XstartOnFirstThread
-Dorg.eclipse.swt.internal.carbon.smallFonts
-XX:MaxPermSize=256m
-Xms40m
-Xmx1060m
-Xdock:icon=../Resources/Eclipse.icns
-XstartOnFirstThread
-Dorg.eclipse.swt.internal.carbon.smallFonts

The same project (i.e. really the same project, not just the same code) runs without dependency problems in Eclipse Indigo. Edit: Just found out, that this exception is caused by JDK7 and not the Eclipse version used.

like image 291
str Avatar asked Feb 17 '13 18:02

str


2 Answers

I am using the preview version that supports Juno just fine: http://scala-ide.org/download/milestone.html#scala_ide_21_milestone_3

like image 101
EECOLOR Avatar answered Nov 06 '22 10:11

EECOLOR


In the meantime, I managed to solve these problems.

First try:

  • Update to the most current JDK (1.7.0u15 at the moment)
  • Clone the code from Github again
  • Install Eclipse Indigo
    • reinstalling Eclipse solved the problems with JDK6, it now just starts with JDK7 without any further configuration
  • Install the Scala plugin
  • create a new Eclipse project using sbt eclipse
  • import the created project

Oops, does not work! I still get this exception:

value getPlatformMXBean is not a member of object java.lang.management.ManagementFactory

... which is strange because Eclipse now really runs with the JDK7. Without digging any deeper, I just gave Eclipse Juno a shot.

Second Try:

  • Do all the same as above
  • Install Eclipse Juno instead of Indigo
  • Yay, it works! :)

Conclusion:

So I am not sure why, but Eclipse Indigo somehow does not like getPlatformMXBean. It does not appear to be an issue with the JDK but Eclipse itself.

like image 45
str Avatar answered Nov 06 '22 09:11

str