Java 在 Windows 上查找 JRE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3267955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Finding the JRE on Windows
提问by Mike2012
I know this question is going to sound very stupid but here goes nonetheless. I need to bundle the new version of the JRE with my applicaiton and I cannot find either a version of the JRE that is not in .exe nor can I find where the jre is installed to on Windows 7 (windows 7 search cannot find anything so it is not helpful). Can anyone tell me where I can download a version of the JRE the would be good to bundle or where I can find the path that windows installed the JRE too?
我知道这个问题听起来很愚蠢,但仍然如此。我需要将新版本的 JRE 与我的应用程序捆绑在一起,但我找不到不在 .exe 中的 JRE 版本,也找不到在 Windows 7 上安装 jre 的位置(Windows 7 搜索找不到任何东西,所以这没有帮助)。谁能告诉我在哪里可以下载 JRE 的一个版本,可以很好地捆绑,或者我可以在哪里找到 Windows 安装 JRE 的路径?
采纳答案by jfenwick
Not sure about Windows 7 but on Windows XP the installation defaults to C:\Program Files\Java\jre6
不确定 Windows 7,但在 Windows XP 上,安装默认为 C:\Program Files\Java\jre6
回答by Martster
corsiKa is correct about Windows 7 I found that the file path for jre is C:\Program Files (x86)\Java\jre7
corsiKa 对 Windows 7 是正确的我发现 jre 的文件路径是 C:\Program Files (x86)\Java\jre7
For my purposes I needed to install the Connector/J JDBC driver in the ext directory. jre7\lib\ext\
出于我的目的,我需要在 ext 目录中安装 Connector/J JDBC 驱动程序。jre7\lib\ext\
回答by PhiLho
Alternatively, install a JDK, if you haven't done it yet, and take the jre
folder in its installation directory.
或者,安装 JDK(如果您还没有jre
安装),并在其安装目录中获取该文件夹。
The JDK can also install it in Program Files
(64-bit on 64-bit Windows, always on 32-bit Windows) or Program Files (x86)
(32-bit on 64-bit Windows) as explained above.
JDK 还可以将其安装在Program Files
(64 位 Windows 上的 64 位,始终在 32 位 Windows 上)或Program Files (x86)
(64 位 Windows 上的 32 位)中,如上所述。
It also installs java.exe
, javaw.exe
and javaws.exe
in C:\Windows\system32
It will be the last installed version...
它还安装java.exe
,javaw.exe
并且javaws.exe
在C:\Windows\system32
它将是最后安装的版本...
回答by B White
I have found another, more generic solution that I'm using in Powershell. The problem is that Java is now using symlinks to java, javaw and javac, so you can't always rely on using "where.exe java" because it returns the symlink.
我找到了另一个更通用的解决方案,我在 Powershell 中使用。问题是 Java 现在使用指向 java、javaw 和 javac 的符号链接,因此您不能总是依赖使用“where.exe java”,因为它返回符号链接。
I now rely on Java to report where it's actually running from by using verbose mode and parsing the output.
我现在依靠 Java 通过使用详细模式并解析输出来报告它实际运行的位置。
$javapath=((java -verbose -version | ? {$_ -match "Opened" }).replace("[Opened ","")).replace("\lib\rt.jar]","")
It will find the path that java reports it's actually using and return the installation directory. The only problem I haven't quite resolved is that it outputs extra information because of the "-version" option, but the only other option is the help, which is worse. However, when run from a script, the console output can simply be ignored. If someone else has a way of keeping it quiet, I'd like to hear it.
它会找到java报告它实际使用的路径并返回安装目录。我唯一没有完全解决的问题是,由于“-version”选项,它会输出额外的信息,但唯一的其他选项是帮助,这更糟。但是,当从脚本运行时,可以简单地忽略控制台输出。如果其他人有办法保持安静,我想听听。