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. :)

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

  1. Bajrang Says:

    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

  2. Touba Says:

    Thanks for ur useful post.
    goodluck.

  3. Pablo Says:

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

  4. Pablo Says:

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

  5. James Says:

    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! :D

  6. Radhika Says:

    Ur comment is very useful .Thanks.

  7. Mihai Says:

    Thank you! Thank you! Thank you!

  8. Anant Shrivastava Says:

    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 Says:

    can’t get this bit

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

    my website is anantshri [dot] info

  10. P Says:

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

  11. Rajeev Says:

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

  12. Sigh O'Nara Says:

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

  13. Anil Says:

    Many thanks. Yes. MVN plugin was the bitch.

  14. Sasha Says:

    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.

  15. Fedor Says:

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

Leave a Reply