Switching between Java 32-bit and Java-64-bit

I just found out that Apache Tomcat cannot work as a Windows service if I use the 64-bit JDK. Therefore, I additionally installed Java 32-bit on my Windows.

The question is, when I checked the java version using java -version, it still shows that the 64-bit version is still working. How do you switch from 64-bit to 32-bit? It would also be nice to be able to switch back to the 64-bit version later.

+4
source share
3 answers

The question is, when I checked the java version using java -version, it still shows that the 64-bit version is still working.

This is not entirely true. No Java copy yet / already running. (Or, if there is, you are not talking to him when running java -version .)

Actually, this shows that your shell starts 64-bit Java when you give it the java command name. And the reason is that the shell variable% PATH% tells the shell to look in the directory containing the 64-bit version, not the 32-bit version; those. you have not changed it!

What you need to do is change the shell environment variables% PATH% and% JAVA_HOME% to point to the right place. % JAVA_HOME% should point to the installation directory, and the% PATH% variable should include% JAVA_HOME% \ bin.

+7
source

You must set the JAVA_HOME environment variable to the path to the JDK version that you want to use.

In 2000 / XP, see: http://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows

On Windows 7, see http://www.itechtalk.com/thread3595.html (this is not a tutorial for setting the JAVA_HOME variable, but a general environment variable: please adapt to your needs.)

If you want to change the version of Java that you see when running java -version on the command line, you need to change the PATH environment variable so that it contains the path to the JDK bin directory that you want to use. See: http://www.java.com/en/download/help/path.xml
Remember to close the command shell and reopen it after changing the PATH variable.

+1
source

I found that on Windows 7 I had to edit the JAVA_HOME path in the registry entry in several places to completely switch to another path for another Java installation. Changing JAVA_HOME in environment variables is not enough. You can do a quick test yourself:

  • Rename your Java home directory.
  • Update the value of the %JAVA_HOME% environment variable to reflect the new name of your JAVA_HOME .
  • Run java -version in a new command window.

An error message will appear

 Error: could not open `C:\your_java_home_path\jre7\lib\amd64\jvm.cfg' 

Therefore, this is not the same behavior as on Linux, where just changing $JAVA_HOME enough to change the pointer to the new installation directory of your java.

Windows seems to hardcode the java home path in its registry in several places.

 Start --> Run --> regedit 

At HKEY_LOCAL_MACHINE / SOFTWARE / JavaSoft / ... expand each directory and edit every java home path that you find hardcoded for your new JAVA_HOME path in every registry where it occurs.

+1
source

Source: https://habr.com/ru/post/1383172/


All Articles