export JAVA_HOME with spaces in Cygwin

丶灬走出姿态 提交于 2019-11-29 09:45:21

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
user2540312

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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!