3

I'm trying to get the java command to work on my computer. Whenever I try to use it, I get the error "'java' is not recognized as an internal or..."

What I've done
So far I've traced the issue through my system environment variables, which has a variable PATH that links to "C:\ProgramData\Oracle\Java\javapath" or javapath for short.

There are 3 files in the javapath folder, and if you click on them a popup says: enter image description here

But when I examine the properties of the shortcut and click "open folder location" it sends me to the right place (?? what is this).

Just in case, I tried to recreate the shortcut; I called it java2 and it now works (opens a command box for a split second and closes) when I click on it. However, testing it in command prompt with the line "java2 -version" returns "'java2' is not recognized as an internal or external..."

Details
I just installed java 8, and I've verified that it was installed correctly

I'm running a 64 bit windows 7 OS

4
  • you should add the \bin directory inside jdk folder. it's ideally C:/java_folder/jdk_version/bin' - The point is you need bin` folder to be added to PATH. Remove the other things you have added and then see what happens. Also, your commands should be javac myfile.java for compiling and java myclassfilename for executing it. Is there anything you have done differently? Commented Nov 10, 2014 at 20:55
  • I don't know what you did, but for your terminal to recognize java as a process it needs to know of a location that contains java.exe, which you need to add that location to the PATH variable, so like C:/program_files/java/blahblah/bin something like that Commented Nov 10, 2014 at 20:56
  • PATH is a system environment variable, currently it's linking to the "C:\ProgramData\Oracle\Java\javapath" I explained above Commented Nov 10, 2014 at 20:57
  • @hagubear For testing purposes, the only command I've used is "java -version". As for the JDK, I have a jre_version instead. Also, the PATH variable links to a folder with shortcuts to the jre_version... that's just how it was. I don't see how it could cause a problem, and tried linking it directly with the same results. Commented Nov 10, 2014 at 21:03

1 Answer 1

5

Have you checked your environment variables for Windows? When you installed the JDK/JRE the directory should have been added to the PATH variable. The directory added needs to contain the java.exe executable. It should be located in C:\Program Files\Java or something like that if you installed it using the default settings. Once you find that directory find the bin directory inside it.

In order to check that:

  • Right click My Computer and hit Properties
  • On the left side hit Advanced System Settings
  • Hit the Advanced tab and then Environment Variables down at the bottom
  • Find the PATH variable and then hit edit. Confirm that the location of the JDK /bin directory is there, if it is not then add it.

Also, if the JAVA_HOME variable isn't already set, this may be a good idea.

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

4 Comments

My path variable contains the link "C:\ProgramData\Oracle\Java\javapath", which contains shortcuts called "java.exe", "javaw.exe", and "javaws.exe", these shortcuts are linked to their counterparts in "C:\Program Files (x86)\Java\jre1.8.0_25\bin". This doesn't seem to be the problem, I've tried linking directly to the bin folder with no avail
IMHO, I would just go with adding the C:\Program Files (x86)\Java\jre1.8.0_25\bin directory to your path instead of shortcuts. That should work since java.exe is in that directory. I'd try these changes, exit the command prompt and then try again.
... Exiting the command prompt, that was the problem. Thank-you, I've been working on this for hours. (it also only works when the path is set directly to the /bin folder)
Glad you got it! Every time you make a change to the PATH variable or add other environment variables you need to restart the command prompt so it can load up the environment again.

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.