Configuring Eclipse to use a JDK at a location with spaces in it
I was setting up my Eclipse environment with some new plugins today and ran into some trouble, which seems to have bothered many souls as I gather from the posts I found when trying to fix the problem.
Some tools/plugins/features in Eclipse may need to use a JDK rather than a JRE. Sometimes you may even wish to switch between different versions of the JRE or JDK being used since typically 1.4, 1.5/5 and 1.6/6 are all present on a developers’ system at different locations.
I got a mesage from a Maven plugin which said that it needed a JDK to be used to run Eclipse instead of a JRE that it was currently using. Well, this shouldn’t usually present much of a problem. You can choose the virtual machine used to run Eclipse by passing the -vm argument to eclipse.exe. What’s usually needed is something like “eclipse.exe -vm c:\jdk1.6\bin\javaw.exe”. Mind you, javaw.exe is used when you don’t want an associated console window.
I did have JDK 1.6 installed. But it was installed to “C:\Program Files\Java\jdk1.6.0_07″. That, it seems, is the default location. The space in the path caused big problems. I tried quotes\no quotes and other magical incantations to get it to accept the argument with a space but to no avail.
So instead of using the command line switch, I put an entry into eclipse.ini which is in the same directory as eclipse.exe. But this didn’t work either.
Finally, what did work was that I started command.exe (the 16 bit DOS shell) and navigated to the JDK directory using “dir /X” for help which shows names generated in the format “C:\PROGRA~1\JAVA\JDK16~1.0_0\BIN”. Perhaps you remember coming across such filenames.
Anyway, the older 8.3 style directory name worked! My final eclipse.ini is posted below.
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256M
-framework
plugins\org.eclipse.osgi_3.4.0.v20080605-1900.jar
-vm
C:\PROGRA~1\JAVA\JDK16~1.0_0\BIN
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m
I was using Windows XP with SP3 and Eclipse 3.4. There is likely to be a better solution that I missed. If you have it or if this post helped you, please leave a coment.
Related posts:
- Sun JDK 7 released
- Debug with Step Filters in Eclipse
- Conditional breakpoints in Java development with Eclipse
- Eclipse tip: Add a short cut key to Skip All Breakpoints
- Identifying a thread with high CPU usage in a Java app
Tags: Code, Configuration, Eclipse, Java, JDK, Maven, Tips

Thanks a lot… It helped me get rid of the Jdk 1.6 it was always picking…
I also tried the quotes and everything… and even tried to put the vm arg using a shortcut and passing the command line arg but it did not work… the old is gold style seems to work very well.
Thanks again mate…
Cheers
Thanks for ur useful post.
goodluck.
For me, it works by setting it with spaces into eclipse.ini
It’s me again. I’m using eclipse 3.4.0 under Windows XP SP3
Just 5 seconds before I found your post, I’ve figured it out by replacing ‘\’ with ‘/’:
-vm
C:/Program Files/Java/jdk1.6.0_11/bin
and it worked!
And your method is also great! Thanks man!
Ur comment is very useful .Thanks.
Thank you! Thank you! Thank you!
just a quick suggestion
try putting “\ ” instead of ” ” that should help
what i mean is that escape all spaces with a backslash
Hope that helps.
can’t get this bit
if i put my site in website your wordpress says comment discarded.
my website is anantshri [dot] info
Err, odd. Might be due to to some WordPress spam filter.
Thank you for your post! It helps me to solve similar issue you were getting..
Mine works fine without any error.
-vm
c:\Program Files\Java\jdk1.6.0_13\bin
Thank you for this. Very helpful and I no longer get that annoying message.
Many thanks. Yes. MVN plugin was the bitch.
Mine works without any errors as well. I had the same problem, and it ended up being because the -vm option was located below the -vmargs option in the ini file. Once I moved it up, everything worked fine, even with spaces.
Thanks everyone. By combining Onkar’s tip with those of several of the commenters I finally fixed the problem!
I was loosing the will to live until I found this post. Thanks a lot!
Thanks buddy! I had been struggling with this thing for past 1/2 hour!! … eclipse documentation must be updated with this (that -vm needs the path all the way uptil /bin folder! )
Thanks!
Gautam
@Gautam
Pleasure to have been of help.
THANK YOU! Saved our bacon.
Hi,
I have the same issue and my eclipse is running on jre. But Maven needs JDK to download all the dependencies.
I am going to try the above suggestions.
Thanks guys!
Sridevi