简体   繁体   中英

Switch between 32-bit and 64-bit JDK platform on Windows 7

I am using Windows 7 on my laptop. I am working with jpcap libraries which work only on 32-bit JDK. Having both 32 and 64 bit JDKs installed on my machine. How can I switch between 64-bit and 32-bit JDK?

I tried changing the %JAVAHOME% and %PATH% environment variables, but it didn't work. Should I change anything in the registry?

You can either set your path, or switch between JDK's in your IDE. Personally I use JetBrains IntelliJ IDEA and set the JDK via the IDE.

Setting via IDE:

From within a project:

  • click File -> Project Structure
  • Select Project under Project Settings
  • Select the Project SDK. If yours is not listed, click New -> JDK and browse for the JDK

在此输入图像描述 From a new project:

  • Click File -> New Project
  • Select the Project SDK. If yours is not listed, click New -> JDK and browse for the JDK

If you want to set your path:

Follow the directions listed on the java.com site . Keep in mind that your jar will run using whatever version of java is specified in your PATH.

If your PATH variable is not working, try cleaning up your path variable by removing unnecessary entries and rebooting. After reboot add Java to the path and reboot again.

If your still having issues, try executing using the absolute path of the java version your trying to use to ensure it works. If it does work, check your path variable against it to ensure it is accurate.

@Srikant Sahay, Thank you very much! It did work on widnows 8.1 64 bit OS.

I am able to Switch between 32-bit and 64-bit JDK platform on Windows 8.1 on demand. The trick, as Srikant suggested, is to set the path before all other path variables. Make sure you put fist in the path variable.

java -d32 -version           ( or simply )
java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)

However, only one instance works at a time. Either you choose the 32 bit version or the 64 bit version. So, if you type "java -d64 -version" you will get

Error: This Java instance does not support a 64-bit JVM.
Please install the desired version.

Therefore, if you instead want a 64bit JVM you should put the JDk installation folder(in my case "C:\\Program Files\\Java\\jdk1.7.0_51\\bin" since the OS is 64 bit by default) first in the path variable.

cheers!

No, don't touch the registry. Each running Java application gets a single unique JVM instance. So a single java program cannot run some parts of the code in one JVM and other parts of the code in another JVM, as far as I know. You can, however, choose which JRE a particular java program runs in, so you can run the entire jpcap program in your 32 bit java version. Use a startup script (batch file) that points to the exact location of java.exe. When you run "java MyClassName" it's really just finding the java executable on the PATH environment variable, so by explicitly specifying your path, you get to choose your version. In other words, if you run a java program using "java MyClassName" (or if a program on your machine does so) it will use the java.exe application found on your PATH environment variable. Applications themselves can use whatever environment variables they choose: typically the ones used for java are JAVA_HOME and JRE_HOME . So you might want to try setting both of those and then trying to run your program again.

Set the path of your java in System Environment Variables PATH variable. Set it to be before any other path (even System 32 if java or javaw is present there).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM