3

Trying to execute java.exe and getting the lovely error

>> sh.exe": java.exe: command not found

The command works in a normal command shell.

I've checked the path of both and they are the almost the same, bash has a few extra directories as expected. I used env |grep PATH and set PATH respectively to check...

where java.exe

C:\Windows\System32\java.exe

set PATH
Path=C:\Ruby193\bin;C:\Windows\system32;C:\Windows;

env |grep PATH
HOMEPATH=\
PATH=/c/Users/hooksc/bin:.:/usr/local/bin:/mingw/bin:/bin:/c/Ruby193/bin:/c/Windows/system32:/c/Windows:

I figure I'm missing something subtle, anyone have any ideas what?

I have snippet the path short to make it a bit easier to read... However, at least 1 of the source folders for java.exe is in the path.

1
  • I also am having this problem. Anyone got any ideas? Commented Jun 10, 2013 at 12:22

2 Answers 2

7

Gitbash looks for %PATH% variable. On your gitbash type:

env | grep PATH

and check if it contains the path to your jdk's bin directory. If it doesn't, then you'd have to add the path yourself. For more information on how to add it, follow this link: http://www.java.com/en/download/help/path.xml

Sign up to request clarification or add additional context in comments.

5 Comments

Turns out there is a difference between the system user PATH and the logged in user PATH variables. Java was in the path of the user, not system and the system PATH variable is the one showing up. Not sure why, but adding Java to the system PATH worked.
@Shire You should maybe add that as a separate answer :)
To pull this out into its own answer, I would want to answer why gitbash it using the system PATH instead of the logged in user PATH variable. I am still confused on that bit, just haven't taken the time to figure it out yet.
I'd like to reiterate here that the path to add is to the JDK bin folder not to Java.exe explicitly.
PATH="$PATH":/c/sun/java/jdk1.7/bin
2

Whilst amending system PATH might get around your problem, it doesn't explain why the child process doesn't see the concatenated user PATH.

I had the same problem with Git Bash and eventually found that it was due to my user PATH containing this: %VPROJECT%..\bin; ...but I didn't have a VPROJECT environment variable - somehow this caused the concatenation of user PATH to system PATH to silently fail for child processes (although weirdly it didn't affect the initial bash shell, adding to the difficulty in finding the problem).

I don't know who's to blame for this - it's one or more of git-bash.exe, bash.exe and sh.exe not coping. And of course, whatever added that path without adding the corresponding environment variable (or possibly whatever removed the environment variable without removing the path).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.