This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm running into problems loading a Java IDE due to it not being able to find the JRE. I set the environment variables as instructed, but this didn't help.
While troubleshooting the problem, I ran into something strange. I opened the command prompt and tried to get my JRE version by typing 'java.exe -version'. It threw the following error:
"C:\Documents and Settings\End User>"C:\Program Files\Java\jre7\bin\java.exe" -version
Error: loading: C:\Program Files\Java\jre7\bin\msvcr100.dll
Error: loading: C:\Program Files\Java\jre7\bin\client\jvm.dll
I then ran the same command, but without the .exe. The result is that it worked, as shown below.
"C:\Documents and Settings\End User>"C:\Program Files\Java\jre7\bin\java" -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) Client VM (build 24.0-b56, mixed mode, sharing)
I'm running Windows XP SP3
Can anyone tell me what is the difference between running 'java.exe' and 'java'? What can I do to get the 'java.exe' command to work correctly?
Running a program without specifying an extension means that Windows will try to run an executable file with that name. An executable file could be any file with a .exe, .cmd or .bat extension (there may be others). I'm not sure what Windows does if it finds multiple matching executable files.
Have a look in the C:\Program Files\Java\jre7\bin directory and see if there are any other java.xxx files and then try runing these with the extension. This should give you an indication of which one Windows is running automatically.
When you find it, if it's a .cmd or .bat file then they will probably ultimately call jave.exe but they may do some required configuration first. Both are text files so you can look at their contents to see how they work.
Stuart A. Burkett wrote:I'm not sure what Windows does if it finds multiple matching executable files.
In the good old days of DOS and early Windows it was: .com .exe .bat
These days there is a PATHEXT environment variable which defines the order. ie the order the extensions are listed in is the order of preference. If the PATHEXT variable isn't defined I guess it reverts to the DOS order probably with .cmd coming after .bat.
Welcome to the Ranch
I never knew you could write java.exe -version. You usually simply write java.
As well as running java -version, run javac -version; you should get a result like javac 1.7.0_40. That Java version is as far as I know the most recent available. There is usually only one “java” file in the bin folder: on a Windows box it is java.exe. I have opened my Windows folder and this is its contents
As you say, you appear to have set up your PATH correctly.
Which IDE are you using? You usually have to tell it where to find a java executable, by directing its path to the JDK folder. It varies from IDE to IdE, but you usually direct it to one folder higher than the bin folder. If your PATH is c:\Program Files\Java\jdk1.7.0_40\bin, then direct the IDE to c:\Program Files\Java\jdk1.7.0_40. If there is a space in the PATH, you may need to enclose it in "" quotes.
I think this sounds more like an IDE problem; if I pass you to our IDEs forum, you might get better attention there.
Joined: Oct 09, 2013
Thanks for the answers!
I checked for .BAT, .COM and .CMD files but could not find any in the JRE folder. I also tried changing to the JRE folder before running the 'java' vs. 'java.exe' test, and the results were the same. I will try enclosing the folder name in the PATH statement in quotes and see if that helps.
Ravi - based on the Command windows that pop up when the install is trying to find Java, it is looking in both the JRE and JDK folders. The paths it reports looking in are correct, but it still says it can't find a valid JRE.
Thanks again! Any further help will be greatly appreciated!
Joined: Oct 13, 2005
Assuming you get that response from java -version and a sensible response from javac -version, your PATH environment variable appears correct. I presume you can run Java® programs from the command line, but it is the IDE you are having problems with.
Which IDE is it?