tags:

views:

407

answers:

1

I want to configure my Eclipse environment to use the JDK instead of the standard JRE. I'm doing this because I use m2eclipse, which requires tools.jar from the JDK to run.

I'm running Eclipse 3.5.1 on Windows 7 32-bit with JDK 1.6.0_16.

On my system, I have the JDK installed to "C:\Program Files\Java\jdk" (symlink to the latest install).

I add the -vm option to eclipse.ini to point to the JDK

-vm
C:/Program Files/Java/jdk/bin

I've confirmed that eclipse is in fact starting with the desired JVM. In the configuration details

eclipse.vm=c:/Program Files/Java/jdk/bin\..\jre\bin\client\jvm.dll

Additionally, in my environment,

JAVA_HOME=c:\Program Files\Java\jdk

However, in Window | Preferences | Java | Installed JREs, the only JRE listed is the one in "C:\Program Files\Java\jre6". This JRE ends up being the one under which Maven is run, and so my maven builds fail.

I know I can manually change the Installed JRE to point to the JDK, and this is what I've done in the past. However, I'd like to find a way to script this change so that I can automate the installation of a dev environment.

Where is this setting stored? What is the best way to automatically configure Eclipse to use the JDK as the only Installed JRE?

+2  A: 

The setting is stored in

<workspace>\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.launching.prefs

I would recommend setting your JDK manually in Preferences / Java / Installed JRE, as well as Preferences / Java / Installed JRE / Execution Environment.

Then, whenever you need an eclipse with that exact configuration, just copy over this file with your preset config file, and launch that eclipse.

Extract from that config file:

org.eclipse.jdt.launching.PREF_DEFAULT_ENVIRONMENTS_XML=
  <?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>
  <defaultEnvironments>
      <defaultEnvironment environmentId\="JavaSE-1.6" 
                          vmId\="57,org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType13,1255369536255"/>
  </defaultEnvironments>


 eclipse.preferences.version=1
 org.eclipse.jdt.launching.PREF_VM_XML=
   <?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>
       <vmSettings defaultVM\="57,org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType13,1255369536255">
            <vmType id\="org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType">
                <vm id\="1255369536255" 
                    javadocURL\="http\://java.sun.com/javase/6/docs/api/"
                    name\="jdk1.6.0_16" path\="C\:\\Prog\\Java\\jdk1.6.0_16">
                <libraryLocations>
                    <libraryLocation jreJar\="C\:/Prog/Java/jdk1.6.0_16/jre/lib/resources.jar" 
                                     jreJavadoc\="http\://java.sun.com/javase/6/docs/api/" 
                                     jreSrc\="C\:/Prog/Java/jdk1.6.0_16/src.zip"
                                     pkgRoot\=""/>
VonC
I think it's available somewhere around there but are you sure it's the right file? This is the content on my machine: `eclipse.preferences.version=1`
Pascal Thivent
That may be the content by default, when no JRE is explicitly declared. But if I declare one, then this file does contain a bit more than `eclipse.preferences.version=1`
VonC
Thanks for that confirmation :)
Pascal Thivent
After some further examination, I found that if I simply deleted the org.eclipse.jdt.launching.prefs file and started eclipse that it would add the JDK as the sole Installed JRE. I'm guessing the reason I had to set it manually before was because I must have launched Eclipse early on without one of the above settings (such as the JAVA_HOME environment).Thanks for the pointer. This was a huge help and should save me a good deal of time in the future.
Jason R. Coombs
I am glad you manage to solve this. I will keep this "delete pref file" trick in mind.
VonC