About Me

My photo
I know the last digit of PI

Monday, September 12, 2011

Using older Java on Windows

When JDK 7 is installed it became the default java on the machine. However if you try to set different JDK (by JAVA_HOME and PATH variables) it won't change. The reason is that there is a c:\windows\system32\java.exe wrapper that reads the system registry and executes the java. If you try to change
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion to 1.6 you will get the following error:


C:\Windows\System32>java -help
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'

has value '1.6', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.


I found two solutions on this problem:
1) use -version:1.6 as parameter

java -version:1.6 -jar myprogram.jar

It will run the jar with version 1.6
Of course you can set it into some system property like JAVA_OPT (for tomcat)

2) Add JAVA_HOME environment variable, and put %JAVA_HOME%\bin before %SystemRoot%\system32.
So the JAVA_HOME\bin\java.exe will be found before the c:\windows\system32\java.exe wrapper.

1 comment:

Apekshith Ramesha said...

it worked great! thank you!