0

I'm trying to compile a project in using Git Bash, but i'm having a problem with java.

I have the JDK version 1.8.0.25 installed under the path T:\Program Files\Java\jdk1.8.0_25.

Initially, I tried to set the JAVA_HOME variable via the command in Git like so:

$ JAVA_HOME="T:\Program Files\Java\jdk1.8.0_25" Java -jar BuildTools.jar

This didn't work, I get an unable to locate directory error.

So I tried manually setting the environment variable via the command:

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_25"

Then I ran the compile command without the first part and I get an error saying that the compiler tools were not found in my (JRE) directory. Almost as if its ignoring the environment variable I set and searching the JRE instead of the JDK anyway. Why won't it follow the path I specify?

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
cody
  • 735
  • 3
  • 11
  • 19
  • 5
    Keep in mind that `git` and `git bash` are different things. `git` (to my knowledge) doesn't handle variables for Java globals, but a shell could. Just keep that in mind for the future. This isn't a git problem, but rather a bash/shell problem. – BlackVegetable Dec 15 '14 at 22:40
  • I'm not certain if you are saying I should have worded the question differently or that bash is not capable of doing what i'm trying to do? – cody Dec 15 '14 at 22:48
  • Ah, I mostly just wanted to give you guidance for future questions. I think your confusion (as posted) may be part of the key to answering your question. Keep it as is. – BlackVegetable Dec 15 '14 at 22:50

1 Answers1

0

Are you sure you need to set the actual JAVA_HOME variable? If I remember correctly, for git bash it looks at the $PATH variable for the java version. Maybe try appending your java location here.

also, to double check (sorry if you already know this), you can run the env command to list all your environment variables.

$ env  

Try setting the path and run the java -v command to verify the installation is correct. If not, what is the exact error?

$ java -v

Edit Some more info, to set the $PATH in git windows I think you have to update your $HOME. See this or some other posts (google) for an explanation

Git for Windows: .bashrc or equivalent config files for Git Bash shell

Community
  • 1
  • 1
Justin Maat
  • 1,965
  • 3
  • 23
  • 33
  • So soon i'll update this with some more information but the long and short of it is that updates I make to the PATH and JAVA_HOME variables don't seem to be matching the variables listed in the shell via the $ env command. The PATH variable looks correct when I pull it up through the cmd prompt or in the control panel, but its different in bash, much longer. Like I said I will post more specific information soon. – cody Dec 16 '14 at 04:11
  • Here is what is listed for PATH when I use the env command in bash: PATH=/t/Users/Administrator/bin:.:/usr/local/bin:/mingw/bin:/bin:/bin:/t/Program Files/Java/jdk1.8.0_25:/t/Program Files/Java/jdk1.8.0_25 – cody Dec 16 '14 at 04:19
  • Your using the bash shell so you'll need to set the variable through a .bashrc file. try creating it by going to your user directory (usually the default directory when you open git bash). You can create it by something like the command `notepad ~./bashrc` which will launch notepad. add the export there, something like `export PATH=$PATH:/usr/java/jdk1.8/bin`. You'll need to restart the git bash prompt to see the changes. You can verify by checking the variables again or doing the `java -v` command. Let me know if you have more errors. I meant to install java 8 today too :) – Justin Maat Dec 16 '14 at 05:50
  • I just realized, might be a simple oversight, but you didnt include the \bin directory in your path. Make sure to give the jdk path including bin – Justin Maat Dec 16 '14 at 06:48
  • This is incredibly frustrating this is what i get now: `$ java -v Unrecognized option: -v Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.` Additionally when I attempt to compile, I get this: `[ERROR] Unable to locate the Javac Compiler in: [ERROR] T:\Program Files\Java\jre1.8.0_25\..\lib\tools.jar [ERROR] Please ensure you are using JDK 1.4 or above and [ERROR] not a JRE (the com.sun.tools.javac.Main class is required).` – cody Dec 17 '14 at 02:01
  • I should also mention I get those errors even though the path appears to be correct under env: `PATH=/t/Users/Administrator/bin:.:/usr/local/bin:/mingw/bin:/bin:/t/ProgramData/ Oracle/Java/javapath:/t/Windows/system32:/t/Windows:/t/Windows/System32/Wbem:/t/ Windows/System32/WindowsPowerShell/v1.0/:/usr/java/jdk1.8.0_25/bin` – cody Dec 17 '14 at 02:04
  • hmmmm that's weird. maybe try removing the previous java locations and point it to the jre/bin under that java 8 directory. something like `usr/java/jdk1.8.0_25/jre/bin` or similar. I'm saying this because `\Program Files\Java\jre1.8.0_25\..\lib\tools.jar` is showing that it's looking for tools.jar in 1 directory up and in the lib folder. – Justin Maat Dec 17 '14 at 04:04