我的情况是,我已经安装了JDK,但无法在浏览器中运行小程序(我可能没有安装JRE)。
但是,当我安装 JRE 时,它会破坏我的 JDK 作为默认运行时的能力。 这几乎破坏了一切(Eclipse、Ant)——因为它们需要服务器 JVM。
现在没有 JAVA_HOME
环境变量 - 它似乎只是使用了一些注册表魔法(设置系统路径也没有用)。 以前,我在使用 JRE 恢复 JDK 后刚刚将其卸载。 这次我想好好修复一下。
jre 自动更新程序也体现了这一点 - 曾几何时,我使用 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).
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.
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.
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.
发布评论
评论(9)
这在 Windows 上有点痛苦。 这就是我所做的。
在
c:\install\jdk\sun\6u11
路径中安装最新的Sun JDK,例如6u11,然后让安装程序在默认位置安装公共JRE(>c:\program files\blah
)。 这将为大多数事情设置默认的 JRE。根据需要安装较旧的 JDK,例如
c:\install\jdk\sun\5u18
中的 5u18,但不要安装公共 JRE。在开发过程中,我有一个小批处理文件,用于为每个 JDK 版本设置命令提示符。 本质上只需设置
JAVA_HOME=c:\jdk\sun\JDK_DESIRED
,然后设置PATH=%JAVA_HOME%\bin;%PATH%
。 这会将所需的 JDK 放在路径的首位,任何辅助工具(例如 Ant 或 Maven)都可以使用JAVA_HOME
变量。该路径很重要,因为大多数公共 JRE 安装都会将链接的可执行文件放在
c:\WINDOWS\System32\java.exe
中,这通常覆盖大多数其他设置。This is a bit of a pain on Windows. Here's what I do.
Install latest Sun JDK, e.g. 6u11, in path like
c:\install\jdk\sun\6u11
, then let the installer install public JRE in the default place (c:\program files\blah
). This will setup your default JRE for the majority of things.Install older JDKs as necessary, like 5u18 in
c:\install\jdk\sun\5u18
, but don't install the public JREs.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:\jdk\sun\JDK_DESIRED
and then setPATH=%JAVA_HOME%\bin;%PATH%
. This will put the desired JDK first in the path and any secondary tools like Ant or Maven can use theJAVA_HOME
variable.The path is important because most public JRE installs put a linked executable at
c:\WINDOWS\System32\java.exe
, which usually overrides most other settings.我已将属性对话框中的 Eclipse 启动快捷方式的行为
从
修补为
在 Eclipse 文档中
它只是一个补丁,因为它取决于修复问题的快捷方式...
替代方法是设置参数永久存在于 eclipse 初始化文件中。
I have patched the behaviour of my eclipse startup shortcut in the properties dialogue
from
to
as described in the Eclipse documentation
It is a patch only, as it depends on the shortcut to fix things...
The alternative is to set the parameter permanently in the eclipse initialisation file.
我刚刚遇到了这个问题(Windows 7 上的 Java 1.8 与 Java 9),我的发现是:
短版本
默认似乎是(因为路径条目)
选择您想要的版本(测试,使用选项卡在 cmd 中完成,不确定这些数字代表什么),我有 2 个选项,请参阅更长的版本以了解详细信息,
删除连接/链接并链接到您的版本(在我的情况下,Java 8 以 181743567 结尾)
更长的版本:
Java 9 不起作用后重新安装 Java 1.8。 安装顺序是jdk1.8.0_74,jdk-9.0.4并尝试使Java 8默认为jdk1.8.0_162...
安装jdk1.8.0_162后我仍然有
我在路径中看到的是
所以我检查了什么我发现它是一个连接点(链接),
这些哈希值并没有敲响警钟,但是当我检查
以便再次使 Java 8 默认时,我必须按照所述删除链接 此处
并使用我想要测试的 Java 重新创建
:
** 更新 (Java 10) **
使用 Java 10 类似,只有 javapath 位于 c:\Program Files (x86)\Common Files\Oracle\Java\ 中,这很奇怪,因为我安装了 64 位恕我直言
I just had that problem (Java 1.8 vs. Java 9 on Windows 7) and my findings are:
short version
default seems to be (because of Path entry)
select the version you want (test, use tab completing in cmd, not sure what those numbers represent), I had 2 options, see longer version for details
remove junction/link and link to your version (the one ending with 181743567 in my case for Java 8)
longer version:
Reinstall Java 1.8 after Java 9 didn't work. The sequence of installations was jdk1.8.0_74, jdk-9.0.4 and attempt to make Java 8 default with jdk1.8.0_162...
After jdk1.8.0_162 installation I still have
What I see in path is
So I checked what is that and I found it is a junction (link)
Those hashes doesn't ring a bell, but when I checked
so to make Java 8 default again I had to delete the link as described here
and recreate with Java I wanted
tested:
** update (Java 10) **
With Java 10 it is similar, only javapath is in c:\Program Files (x86)\Common Files\Oracle\Java\ which is strange as I installed 64-bit IMHO
经过多次尝试,我发现路口的做法更方便。 这与 Linux 中解决这个问题的方式非常相似。
基本上,它包括在
c:\tools\java\default
和您想要在系统中默认使用的 java 的实际版本之间建立一个链接。##如何设置:
环境变量
-
PATH
指向 ONLY 此 jrec:\tools\java\default\bin
-
JAVA_HOME
指向 `c:\tools\java\defaultC:\tools\Java\JRE_1.6
C:\tools\Java\JRE_1.7
C:\tools\Java\JRE_1.8
C:\tools\Java\
junction default JRE_1.6
这将创建一个 连接(或多或少类似于 Linux 中的符号链接)
C:\tools\java\ default
和C:\tools\java\JRE_1.6
这样,您的默认 java 就始终位于
c:\tools\java\default
中。如果您需要将默认 java 更改为 1.8 版本,则只需执行
然后您可以使用批处理文件来执行此操作,而无需命令提示符,例如
set_jdk8.bat
set_jdk7.bat
根据 @С֏аџdеМаятіи
编辑的建议:从 Windows 版本 > XP 开始,您应该使用
mklink /J default JRE_1.8
After many attempts, I found the junction approach more convenient. This is very similar on how this problem is solved in linux.
Basically it consists of having a link between
c:\tools\java\default
and the actual version of java you want to use as default in your system.##How to set it:
environment variable
-
PATH
pointing to ONLY to this jrec:\tools\java\default\bin
-
JAVA_HOME
pointing to `c:\tools\java\defaultC:\tools\Java\JRE_1.6
C:\tools\Java\JRE_1.7
C:\tools\Java\JRE_1.8
C:\tools\Java\
junction default JRE_1.6
This will create a junction (which is more or less like a symbolic link in linux) between
C:\tools\java\default
andC:\tools\java\JRE_1.6
In this way you will always have your default java in
c:\tools\java\default
.If you then need to change your default java to the 1.8 version you just need to execute
Then you can have batch files to do that without command prompt like
set_jdk8.bat
set_jdk7.bat
As suggested from @СӏаџԁеМаятіи
EDIT: From windows versions >XP , you should use
mklink /J default JRE_1.8
我只需安装我需要的所有 JDK 版本,最新安装的版本将成为默认版本,因此我只需在必要时重新安装我想要默认的版本。
I simply install all the versions of JDK I need and the latest installed becomes default, so I just reinstall the one I want to be default if necessary.
我在
C:\Java
中安装了多个 JDK(1.4、1.5、1.6)及其 JRE。 然后我让 Sun 更新C:\Program Files\Java
中的公共 JRE。最近有一个改进,安装在jre6中。 以前,每个新版本都有一个不同的文件夹(1.5.0_4、1.5.0_5 等),这会占用大量空间
I have several JDK (1.4, 1.5, 1.6) installed in
C:\Java
with their JREs. Then I let Sun update the public JRE inC:\Program Files\Java
.Lately there is an improvement, installing in jre6. Previously, there was a different folder per new version (1.5.0_4, 1.5.0_5, etc.), which was taking lot of space
需要从环境中删除 C:\Program Files (x86)\Common Files\Oracle\Java\javapath 并替换为 JAVA_HOME,这对我来说效果很好
Need to remove C:\Program Files (x86)\Common Files\Oracle\Java\javapath from environment and replace by JAVA_HOME which is works fine for me
运行 .jar 应用程序的一种可变方法是为其创建 .bat cmd。
例如,您的电脑上安装了jre10和jre8,jre10是您的默认jre。
但是你的jar被指定为与jre8一起使用,以下cmd将起作用:
an alterable way to run an .jar app is create an .bat cmd for it.
for example, you have jre10 and jre8 installed on your pc,and jre10 is your default jre.
but your jar is specified to work with jre8,following cmd will work:
这个问题已被解决,并已在 2020、Windows 10 中得到解决。 我使用的是Java 8 RE和14.1 JDK,它运行良好,直到Eclipse升级到版本2020-09 。 之后,我无法运行 Eclipse,因为它需要使用 Java 11 或更高版本,并且仅找到 8 版本。 这是因为“Path”环境变量的顺序:
我想
C:\Program Files (x86)\Common Files\Oracle\Java\javapath< /code> 是链接到已安装的 JRE exe 文件的路径(在我的例子中是 Java 8),通过在
%JAVA_HOME%
之后向下移动此链接解决了问题,导致到 Java 14.1/bin 文件夹。似乎环境变量的顺序会影响请求可执行文件时搜索文件夹的顺序。
感谢您的评论或更好的解释。
Stacked by this issue and have resolved it in 2020, in Windows 10. I'm using Java 8 RE and 14.1 JDK and it worked well until Eclipse upgrade to version 2020-09. After that I can't run Eclipse because it needed to use Java 11 or newer and it found only 8 version. It was because of order of environment variables of "Path":
I suppose
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
is path to link to installed JRE exe files (in my case Java 8) and the issue was resolved by move down this link after%JAVA_HOME%
, what leads to Java 14.1/bin folder.It seems that order of environment variables affects order of searched folders while executable file is requested.
Thanks for your comment or better explanation.