开发者

Why does java -version return an old version?

OS: Windows XP

I am using yuicompressor-2.4.2 to compress some CSS before uploading to my server. But when I run it, the following exception appears:

Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/yahoo/platform/yui/compressor/Bootstrap (Unsupported major.minor version 48.0)

So I think it's because of the JRE.

I typed in the command:

cmd: java -version

And it says:

java version "1.3.1_01"

But it shou开发者_JS百科ld say 1.6.0_16, since I have installed the latest version.

What should I do to make Java use the latest version instead of the old one?


Set the environment variable JAVA_HOME pointing to the directory where you have jdk 1.6.0

set JAVA_HOME=your_path_to_jdk1.6
set PATH=%JAVA_HOME%/bin;.;..;%PATH%

That's from a command window. Also you can do it from "My PC > Properties > Advanced > Environment variables"


Go to the system32 directory C:\Windows\System32 and delete following 3 files

  • java.exe
  • javaw.exe
  • javaws.exe

Now create a JAVA_HOME environment variable with value={root path of your jdk installation} and add the path till bin folder of your jdk in the PATH environment variable.

Open a fresh command prompt and run java -version to confirm the change


If you are using windows 7/10 go to command prompt and type

where java

Delete all the symbolic link shows below other than your actual installation directory.

Even if correctly added all the environment variables still sometime you can get wrong versions especially when you have multiple version installed in your system and want to switch between them.


On Windows, the JRE installs a java executable in the Windows directory, which should be the first java in your path. This is just a wrapper that looks in the Windows Registry to find the Java home directory (should be "%SystemDrive%\Program Files\Java\jre6" for Java 6) and runs using the libraries there.

Run %SystemRoot%\system32\java -version and see what you get. If that is Java 6, you have entries in your path before %SystemRoot%\system32 (which really should be first). Either fix your %PATH% variable, or you'll have to be explicit whenever you want to run this version of Java.

If running that instance of java doesn't report Java 6, its not installed (correctly). Uninstall and try installing again.

If you are having trouble because of the PATH, it is because you or some software you installed monkeyed with it; I recommend using the default which is to have system32 first. Everything works fine if the defaults are used.

Also, %JAVA_HOME% is not used by the JRE itself at all. Some common Java applications like tomcat and ant honor the %JAVA_HOME% setting, so perhaps yuicompressor does too. But this is a de facto convention, not a standard.


after where java in Command prompt
for example

where java
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-11.0.10\bin\java.exe

delete C:\Program Files\Common Files\Oracle folder then close all terminals and write java -version in the terminal. it will show the right version
worked for me


You should modify your PATH environment variable:

My PC > Right click > properties > Advanced > Environment variables

And modify "Path"

Append at the end the path to your 1.6 installation:

;C:\jdk1.6.xxx\bin

and remove the previous one if present.


Add %JAVA_HOME%/bin to your PATH environment variable where JAVA_HOME is set to your JRE6u16 directory


I had the same problem. In System Properties > Environment Variables > System Variables > PATH make sure there is no other path associated with Java. To make sure, type in and check Java paths.

where java

Re-open Command Prompt and type java -version again. I hope this helps.


first by the following command, you should be aware of .exe file which runs when you type java in the command prompt

where java
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-11.0.10\bin\java.exe

as you see above , cmd first reads java from

C:\Program Files\Common Files\Oracle\Java\javapath

so go to the path above and remove java files . then it should work fine


You should check your PATH environment variable. It is possible that some application you have installed has put its version of the jre in front of yours in the path.


It looks like the older Java version is still on the system PATH environment variable (where the OS looks for commands) or JAVA_HOME (where yuicompressor may look for the java executable)

How those variables are changed depends on your operating system.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜