Reputation: 2318
I have just found out that Apache Tomcat cannot run as a Windows service if I'm using a 64-bit JDK. Therefore I have additionally installed Java 32-bit on my Windows.
The question is when I checked the java version using java -version, it still shows that 64-bit is still running. How do you switch from 64-bit to 32-bit? It would also be nice to have the ability to switch back to 64-bit later as well.
Upvotes: 4
Views: 27429
Reputation: 19
I found that on Windows 7, I had to edit the JAVA_HOME
path in the registry entries in multiple places in order to completely switch to a different path for another java installation. Changing JAVA_HOME
in the environment variables is not enough. You can do a quick test yourself:
%JAVA_HOME%
environment variable value to reflect the
new name of your JAVA_HOME
.java -version
in a new command window.You will get an error message saying
Error: could not open `C:\your_java_home_path\jre7\lib\amd64\jvm.cfg'
Therefore, it's not the same behavior as on Linux where simply changing $JAVA_HOME
is enough to change your pointer to a new installation directory of your java.
Looks like Windows hard codes the java home path in its registry in multiple places.
Start --> Run --> regedit
Under HKEY_LOCAL_MACHINE / SOFTWARE / JavaSoft / ...
expand each directory and edit every java home path that you find hard coded to your new JAVA_HOME
path in each registry where it occurs.
Upvotes: 1
Reputation: 718758
The question is when I checked the java version using java -version, it still shows that 64-bit is still running.
That's not strictly true. There is no copy of Java still / already running. (Or if there is, you aren't talking to it when you run java -version
.)
What this actually shows is that your command shell runs a 64-bit Java when you gave it the command name java
. And the reason for that is that shell's %PATH% variable is telling the shell to look in the directory containing the 64-bit version, rather than the 32-bit version; i.e. you haven't changed it!
What you need to do is to change the shell's %PATH% and %JAVA_HOME% environment variables to point to the correct place. The %JAVA_HOME% should point to the installation directory, and the %PATH% variable should include %JAVA_HOME%\bin.
Upvotes: 7
Reputation: 11403
You have to set the JAVA_HOME
environment variable to the path of the JDK version you want to use.
For 2000/XP see: http://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows
For Windows 7 see: http://www.itechtalk.com/thread3595.html (this is not a tutorial to set the JAVA_HOME
variable, but a generic environment variable: please adapt to your needs.)
If you want to change the Java version you see when running java -version
on the command line, then you have to change the PATH
environment variable so that it contains a path to the bin
directory of the JDK you want to use. See: http://www.java.com/en/download/help/path.xml
Remember to close the command shell and re-open it after you change the PATH
variable.
Upvotes: 1