0

The javac -version gives the proper version of javac. But, java -version gives the error as

"System cannot execute the specified program"

The PATH variable is set properly as "C:\Program Files\Java\jdk1.8.0_102\bin"

Image of CMD

DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44

3 Answers3

0

It is not programming question. But you have to add your %JRE_HOME%\bin to PATH variable

Anton Kolyaev
  • 306
  • 2
  • 10
0

That specific error is likely related to the evaluation of a symlink to the java executables.

Normally, an invalid executable name (meaning, one that is not found in the path) will yield an error with the following text:

'javax' is not recognized as an internal or external command, operable program or batch file.

As you are receiving a different error, this is likely not your issue.

When java is installed on a Windows PC, the installer creates a directory (usually with the path of C:\ProgramData\Oracle\Java\javapath, and places 3 symlinks in it. They are for java.exe, javaw.exe, and javaws.exe. This prevents your path from becoming too cluttered with potentially colliding executable names.

javac.exe (and keytool, etc) work because you added your JRE/JDK bin folder to your PATH. But why does doesn't java/javaw/javaws work? Because it finds the javapath directory above first (PATH is searched left to right). You can see this issue by using the where command. For example:

C:\>where java
  C:\ProgramData\Oracle\Java\javapath\java.exe
  C:\Program Files (x86)\Java\jre1.8.0_31\bin\java.exe

C:\>where keytool
  C:\Program Files (x86)\Java\jre1.8.0_31\bin\keytool.exe

This would be an alright situation, except that the javapath\java.exe symlink is not working, a policy is disallowing its execution, or its path is wrong.

From an administrative command prompt, run the following command. The result should be similar to below

C:\>fsutil behavior query SymlinkEvaluation
    Local to local symbolic links are enabled.
    Local to remote symbolic links are disabled.
    Remote to local symbolic links are disabled.
    Remote to remote symbolic links are disabled.

If "Local to local" symbolic links are disabled, that is your problem (as this settings prevents the following reparse points)

You can enable them with the following command: fsutil behavior set SymlinkEvaluation L2L:1

Double check that the setting changed with the query subcommand. You do not have to restart for this setting to take effect.

If that does not resolve your issue, ensure that the destination of the symlink exists. Try running it via Explorer; a console dialog should pop up then close. If it does not, an easy way to confirm it's correct is to right click the symlink and select "Open File Location". If a error dialog appears stating 'Problem with Shortcut: The item 'java.exe' that this shortcut refers to has been changed or moved [...]', then the path is incorrect.

You can see what the path is set to via the 'Shortcut' tab in the properties of the symlink. If the path is wrong, you can delete the symlink and then recreate it via the mklink command. Delete the symlink and then from an administrative command prompt, run the following; be sure to replace the second path with that of your actual JRE/JDK!

mklink C:\ProgramData\Oracle\Java\javapath\java.exe "C:\Program Files (x86)\Java\jre1.8.0_91\bin\java.exe"

At that point, run 'java' from the command line and see if it works.

If it does not, navigate to your desired java.exe, view its file properties, and ensure there is no "Unblock" button available on the bottom. If there is, click it.

gpg
  • 1
  • 3
-1

you need to set the PATH variable(jre/bin/) in environment settings. in cmd , set PATH ="C:/ProgramFiles/java/jre*/bin"

Chips
  • 65
  • 1
  • 9