Java is not a “Program Files”


I don’t know how many times I’ve been through the scenario. Key “java.sun.com” into the address bar. Click around a few times, getting side tracked by JavaFX or the new WTK or whatever. “Where’s that JDK link again?” Finally find the link to the JDK. Check the box next to the link. “Wait a sec! I can just click the link.” Begin the lengthy download. Begin the install process. Hi, I’m Cliff. You’re here because you put your JDK under “C:\Program Files”. No matter how many times I go through the process, I always make the same mistakes. I always get distracted by some non-jdk link that spins me off on a tangent. I always get confused which link is the JDK, which is the JRE, which one is yucky EJB. I always check the box next to the download link but never use Sun’s download manager. (Who needs to install yet another piece of software to download one file?) And I always, ALWAYS get tempted to install the JDK under “C:\Program Files”.

If you’re new to this site, relax. There’s a strong point buried somewhere in the text. If you’re new to java don’t install to “C:\Program Files”. It’s tempting but dangerous. Here’s what’ll happen. You complete your install. Everything is cool and you’re now a Java programmer. The birds will sing at 7am and the espresso will smell just splendid. Then one day it will happen. You’re running a piece of software, written in Java. You’re getting some crazy error, yet you’ve followed the instructions to the letter. You’re frustrated beyond belief. You write to all the user forums with no definitive answer. Eventually one day (several months later), a piece of the error message becomes clear. The program is complaining about invalid argument, “Files”. If you know like I know, you’ll realize the problem is rooted in the way some apps (Laszlo, Maven plugins, etc.) attempt to track down your local Java installation, then reuse the path as a command line string without quoting or escaping for potential white-space. In other words, somewhere the app is saying, “set JDKHOME = where your jDKHOME is installed. Ok, now run JDKHOME/bin/javac somefiles”. When JDKHOME expands, the whitespace is interpreted as the end of the comand and the beginning of your arguments. You end up running a command named “C:\Program” and giving it an initial argument “Files/bin/javac”. The command interpreter does not recognize C:\Program as a command or an executable file so it coughs.

3 Comments

  1. Too bad Windows has no symlinks. ln -s "C:\Program Files\Java" "C:\Java" would be the easy way to fix the problem.

  2. No, Windows DOES have sym links. They’re called Junction points and there’s a little program that enables them from Explorer’s right mouse menu. I think its called Windows Junction or WinXP sym link or something. (You’ll have to forgive me, I’m in the middle of Chucky Cheese with my two girls and there’s too much going on for me to concentrate/remember). That’s actually not a bad idea, sym link “C:\Program Files\Java” to “C:\Java”.

  3. Woz

    Go old school: Set your JAVA_HOME to the 8.3 name.

    i.e. JAVA_HOME=C:\Progra~1\Java

    (this assumes you do not have another directory that starts with “progra” before Program Files)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 250 other followers

%d bloggers like this: