简体   繁体   English

在Windows 7上在32位和64位JDK平台之间切换

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

I am using Windows 7 on my laptop. 我在笔记本电脑上使用Windows 7。 I am working with jpcap libraries which work only on 32-bit JDK. 我正在使用仅适用于32位JDK的jpcap库。 Having both 32 and 64 bit JDKs installed on my machine. 在我的机器上安装了32位和64位JDK。 How can I switch between 64-bit and 32-bit JDK? 如何在64位和32位JDK之间切换?

I tried changing the %JAVAHOME% and %PATH% environment variables, but it didn't work. 我尝试更改%JAVAHOME%%PATH%环境变量,但它不起作用。 Should I change anything in the registry? 我应该在注册表中更改任何内容吗?

You can either set your path, or switch between JDK's in your IDE. 您可以设置路径,也可以在IDE中的JDK之间切换。 Personally I use JetBrains IntelliJ IDEA and set the JDK via the IDE. 我个人使用JetBrains IntelliJ IDEA并通过IDE设置JDK。

Setting via IDE: 通过IDE设置:

From within a project: 从项目内:

  • click File -> Project Structure 单击文件 - >项目结构
  • Select Project under Project Settings 选择项目设置下的项目
  • Select the Project SDK. 选择Project SDK。 If yours is not listed, click New -> JDK and browse for the JDK 如果未列出您的,请单击“新建” - >“JDK”并浏览JDK

在此输入图像描述 From a new project: 来自一个新项目:

  • Click File -> New Project 单击文件 - >新建项目
  • Select the Project SDK. 选择Project SDK。 If yours is not listed, click New -> JDK and browse for the JDK 如果未列出您的,请单击“新建” - >“JDK”并浏览JDK

If you want to set your path: 如果要设置路径:

Follow the directions listed on the java.com site . 按照java.com站点上列出的说明进行操作 Keep in mind that your jar will run using whatever version of java is specified in your PATH. 请记住,您的jar将使用PATH中指定的任何Java版本运行。

If your PATH variable is not working, try cleaning up your path variable by removing unnecessary entries and rebooting. 如果您的PATH变量不起作用,请尝试通过删除不必要的条目并重新启动来清理路径变量。 After reboot add Java to the path and reboot again. 重启后,将Java添加到路径并重新启动。

If your still having issues, try executing using the absolute path of the java version your trying to use to ensure it works. 如果您仍有问题,请尝试使用您尝试使用的java版本的绝对路径来确保其正常工作。 If it does work, check your path variable against it to ensure it is accurate. 如果确实有效,请检查路径变量以确保其准确性。

@Srikant Sahay, Thank you very much! @Srikant Sahay,非常感谢! It did work on widnows 8.1 64 bit OS. 它确实适用于widnows 8.1 64位操作系统。

I am able to Switch between 32-bit and 64-bit JDK platform on Windows 8.1 on demand. 我可以根据需要在Windows 8.1上切换32位和64位JDK平台。 The trick, as Srikant suggested, is to set the path before all other path variables. 正如Srikant所建议的那样,技巧是在所有其他路径变量之前设置路径。 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. 您可以选择32位版本或64位版本。 So, if you type "java -d64 -version" you will get 所以,如果你输入“java -d64 -version”,你就会得到

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. 因此,如果您想要一个64位JVM,您应该首先在路径变量中放置JDk安装文件夹(在我的情况下为“C:\\ Program Files \\ Java \\ jdk1.7.0_51 \\ bin”,因为操作系统默认为64位) 。

cheers! 干杯!

No, don't touch the registry. 不,请勿触摸注册表。 Each running Java application gets a single unique JVM instance. 每个运行的Java应用程序都获得一个唯一的JVM实例。 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. 因此,据我所知,单个java程序无法在一个JVM中运行代码的某些部分,而在另一个JVM中运行代码的其他部分。 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. 但是,您可以选择运行特定Java程序的JRE,因此您可以在32位Java版本中运行整个jpcap程序。 Use a startup script (batch file) that points to the exact location of java.exe. 使用指向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. 当您运行“java MyClassName”时,它实际上只是在PATH环境变量上找到java可执行文件,因此通过明确指定您的路径,您可以选择您的版本。 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. 换句话说,如果您使用“java MyClassName”运行java程序(或者如果您的机器上的程序这样做),它将使用PATH环境变量中的java.exe应用程序。 Applications themselves can use whatever environment variables they choose: typically the ones used for java are JAVA_HOME and JRE_HOME . 应用程序本身可以使用他们选择的任何环境变量:通常用于java的是JAVA_HOMEJRE_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. 在System Environment Variables PATH变量中设置java的路径。 Set it to be before any other path (even System 32 if java or javaw is present there). 将它设置为任何其他路径之前(如果存在java或javaw,则甚至是系统32)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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