如何设置默认 Java 安装/运行时 (Windows)? [英] How do I set the default Java installation/runtime (Windows)?

查看:19
本文介绍了如何设置默认 Java 安装/运行时 (Windows)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 JDK,但我无法在浏览器中运行小程序(我可能没有安装 JRE).

I'm in the situation where I've installed the JDK, but I can't run applets in browsers (I may not have installed the JRE).

但是,当我安装 JRE 时,它破坏了我的 JDK 作为默认运行时.这几乎破坏了一切(Eclipse、Ant)——因为它们需要一个服务器 JVM.

However, when I install the JRE, it clobbers my JDK as the default runtime. This breaks pretty much everything (Eclipse, Ant) - as they require a server JVM.

现在没有 JAVA_HOME 环境变量 - 它似乎只是使用了一些注册表魔法(设置系统路径也没有用).以前,我在使用它恢复JDK后刚刚卸载了JRE.这次我想好好修复一下.

There's no JAVA_HOME environment variable these days - it just seems to use some registry magic (setting the system path is of no use either). Previously, I've just uninstalled the JRE after I've used it to restore the JDK. This time I want to fix it properly.

这也体现在 jre 自动更新程序上——曾几何时,我有一个使用 JDK 和 JRE 的工作设置,但它更新并破坏了一切.

This also manifests itself with the jre autoupdater - once upon a time, I had a working setup with the JDK and JRE, but it updated and bust everything.

推荐答案

这在 Windows 上有点麻烦.这就是我所做的.

This is a bit of a pain on Windows. Here's what I do.

安装最新的 Sun JDK,例如6u11,在c:installjdksun6u11这样的路径下,然后让安装程序在默认位置(c:program fileslah).这将为大多数事情设置您的默认 JRE.

Install latest Sun JDK, e.g. 6u11, in path like c:installjdksun6u11, then let the installer install public JRE in the default place (c:program fileslah). This will setup your default JRE for the majority of things.

根据需要安装较旧的 JDK,例如 c:installjdksun5u18 中的 5u18,但不要安装公共 JRE.

Install older JDKs as necessary, like 5u18 in c:installjdksun5u18, but don't install the public JREs.

在开发过程中,我有一个小批处理文件,用于为每个 JDK 版本设置命令提示符.基本上只需设置JAVA_HOME=c:jdksunJDK_DESIRED,然后设置PATH=%JAVA_HOME%in;%PATH%.这会将所需的 JDK 放在路径中的首位,并且任何辅助工具(如 Ant 或 Maven)都可以使用 JAVA_HOME 变量.

When in development, I have a little batch file that I use to setup a command prompt for each JDK version. Essentially just set JAVA_HOME=c:jdksunJDK_DESIRED and then set PATH=%JAVA_HOME%in;%PATH%. This will put the desired JDK first in the path and any secondary tools like Ant or Maven can use the JAVA_HOME variable.

路径很重要,因为大多数公共 JRE 安装将链接的可执行文件放在 c:WINDOWSSystem32java.exe,通常覆盖大多数其他设置.

The path is important because most public JRE installs put a linked executable at c:WINDOWSSystem32java.exe, which usually overrides most other settings.

这篇关于如何设置默认 Java 安装/运行时 (Windows)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆