I'm trying to set my JAVA_HOME in Cygwin with this command:
export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.7.0_10"
But when I do cd $JAVA_HOME
, I'd get this error:
$ cd $JAVA_HOME
-bash: cd: /cygdrive/c/Program: No such file or directory
I tried quoting, and escaping the space (ie., \
), but none worked.
Any idea what else would?
Thanks,
I faced this problem too and I saw many posts but nothing really worked. There is a small trick that I did and things started working.
My JAVA_HOME was set to C:/Program Files/Java/jdk1.7.0_23. The problem was with Program Files directory and I was getting the same error.
In Windows there is a short name created for every directory with a space which is without a space. You can see it by running dir /X command on the command prompt. The Short name for Program Files was PROGRA~1.
In the Windows env variable through My Computer I changed the JAVA_HOME to C:/PROGR~1/Java/jdk1.7.0_23 and in hadoop-env.sh I changed JAVA_HOME to /cygdrv/c/PROGRA~1/Java/jdk1.7.0_23.
It worked fine.
You set JAVA_HOME
correctly. Now let's cd
correctly too.
cd "$JAVA_HOME"
To avoid using the tedious Windows environment variables, and also use the actual path string copied from Windows explorer, I suggest adding the following to your startup script:
TMP=`cygpath -sw "C:\Program Files\Java\jdk1.8.0_31"`
export JAVA_HOME=`cygpath -u $TMP`
The first cygpath
invocation obtains a short, windows path; the second converts it to unix format, which works fine in cygwin.
This will also now work fine:
$ cd $JAVA_HOME
Try to use short name to avoid a space in a path.
"C:\Program Files" should have short name C:\Progra~1 (you can verify it using DOS dir command or entering it into address bar in file explorer).
Set your JAVA_HOME this way:
export JAVA_HOME="/cygdrive/c/Progra~1/Java/jdk1.7.0_10"
Try using the DOS subst command to take the spaces of the JAVA_HOME path name. Assuming drive J; is not mounted or otherwise used.
In a DOS shell
subst j: "C:/Program Files/Java/jdk1.7.0_45"
J: is now an abbreviation for C:/Program Files/Java/jdk1.7.0_45
You can now cd to J:
now run Cygwin and
export JAVA_HOME="J:"
I installed Java outside of "Program Files", specifically in c:\tools. Then you can use cygpath to convert the C:\tools\jdk1.8.0_144 to /cygdrive/c/tools/jdk1.8.0_144
You can give the normal C: directory path, and if surrounded by "" you don't need to escape the space in Program Files.
export JAVA_HOME="C:/Program Files/Java/jdk1.7.0_45"
来源:https://stackoverflow.com/questions/14567191/export-java-home-with-spaces-in-cygwin