15

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 should 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?

Carlos Muñoz
  • 17,397
  • 7
  • 55
  • 80

11 Answers11

19

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"

JuanZe
  • 8,007
  • 44
  • 58
  • 1
    Thanks that worked. =) But i still don't know how when I updated java it didn't change the version automatically :S – Carlos Muñoz Oct 14 '09 at 16:04
  • 1
    It might work, but I think it's a kludge. You shouldn't need to mess with the path if your system is set up correctly. – erickson Oct 14 '09 at 16:09
14

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

  • 3
    this can be also in this directory `C:\ProgramData\Oracle\Java\javapath` you need to delete them also – Sumon Bappi Mar 05 '18 at 05:51
  • I also had to uninstall java from Windows parameters > Add or remove programs – Gweltaz Niquel Aug 23 '18 at 09:33
  • In my case there was a shortcut to originally installed Java at `C:\Program Files (x86)\Common Files\Oracle\Java` as `javapath`. To find out from where java is being served you can use @Masood Moghini's answer below that shows a way to list all the java installations using command `where java` – isuru chathuranga Mar 16 '21 at 02:26
13

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.

Arundev
  • 1,388
  • 23
  • 22
9

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.

erickson
  • 265,237
  • 58
  • 395
  • 493
  • 2
    Awesome tip!! I never thought about this at all. I had added to my path but at the end. As soon as I adjusted the orders it resolved the issue right away. Thanks :) – Stephane Grenier Dec 02 '12 at 06:01
9

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

Vahap Gencdal
  • 1,900
  • 18
  • 17
2

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.

OscarRyz
  • 196,001
  • 113
  • 385
  • 569
2

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

Masood Moghini
  • 374
  • 3
  • 13
1

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

Kevin
  • 30,111
  • 9
  • 76
  • 83
1

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.

asyard
  • 1,743
  • 5
  • 21
  • 43
0

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.

akf
  • 38,619
  • 8
  • 86
  • 96
0

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.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720