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.


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. πŸ™‚

Tags: , , , , , ,
This entry was posted on Thursday, September 25th, 2008 at 6:29 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

21 Responses to “Configuring Eclipse to use a JDK at a location with spaces in it”

  1. Bajrang

    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…

  2. Touba

    Thanks for ur useful post.

  3. Pablo

    For me, it works by setting it with spaces into eclipse.ini

  4. Pablo

    It’s me again. I’m using eclipse 3.4.0 under Windows XP SP3

  5. James

    Just 5 seconds before I found your post, I’ve figured it out by replacing ‘\’ with ‘/’:

    C:/Program Files/Java/jdk1.6.0_11/bin

    and it worked!

    And your method is also great! Thanks man! πŸ˜€

  6. Radhika

    Ur comment is very useful .Thanks.

  7. Mihai

    Thank you! Thank you! Thank you!

  8. Anant Shrivastava

    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.

  9. Anant Shrivastava

    can’t get this bit

    if i put my site in website your wordpress says comment discarded.

    my website is anantshri [dot] info

  10. Onkar Joshi

    Err, odd. Might be due to to some WordPress spam filter.

  11. P

    Thank you for your post! It helps me to solve similar issue you were getting..

  12. Rajeev

    Mine works fine without any error.
    c:\Program Files\Java\jdk1.6.0_13\bin

  13. Sigh O'Nara

    Thank you for this. Very helpful and I no longer get that annoying message.

  14. Anil

    Many thanks. Yes. MVN plugin was the bitch.

  15. Sasha

    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.

  16. Fedor

    Thanks everyone. By combining Onkar’s tip with those of several of the commenters I finally fixed the problem!

  17. Andrew

    I was loosing the will to live until I found this post. Thanks a lot!

  18. Gautam

    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! )


  19. Onkar Joshi

    πŸ™‚ Pleasure to have been of help.

  20. Peter Skov

    THANK YOU! Saved our bacon.

  21. Sridevi

    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!