Windows JAVA HOME 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1229019/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:56:07  来源:igfitidea点击:

Windows JAVA HOME problems

windowsvariablesenvironmentjava-home

提问by Amir Afghani

I'm trying to experiment with OracleHelp for Java on my Windows Vista server. I downloaded Oracle help, and I'm following their installation instructions which states:

我正在尝试在我的 Windows Vista 服务器上使用 OracleHelp for Java。我下载了 Oracle 帮助,并按照他们的安装说明进行操作,其中说明:

  • Unzip the OHJ installation .zip file into a directory of your choice
  • Ensure that you have the JAVA_HOME environment variable set to the location of your compatible Java SE installation
  • In the OHJ installation directory, there is a bin subdirectory containing Windows .cmd files and Unix/Linux shell scripts. On Windows platforms, double click on the .cmd files to launch them (or type the .cmd file name on the command line). On Unix platforms, type "sh scriptName.sh" to execute the shell scripts.

    • ohguide.cmd (ohguide.sh) - launches the Oracle Help Guide documentation
    • choiceDemo.cmd (choiceDemo.sh) - launches a demo of Oracle Help features
    • cshDemo.cmd (cshDemo.sh) - launches a demo of context sensitive help
    • helpsetDemo.cmd (helpsetDemo.sh) - launches the Helpset Previewer for testing your helpsets
    • authoringWizard.cmd (authoringWizard.bat) - launches the Helpset Authoring Wizard
  • 将 OHJ 安装 .zip 文件解压缩到您选择的目录中
  • 确保将 JAVA_HOME 环境变量设置为兼容的 Java SE 安装位置
  • 在 OHJ 安装目录中,有一个 bin 子目录,其中包含 Windows .cmd 文件和 Unix/Linux shell 脚本。在 Windows 平台上,双击 .cmd 文件以启动它们(或在命令行中键入 .cmd 文件名)。在 Unix 平台上,键入“sh scriptName.sh”以执行 shell 脚本。

    • ohguide.cmd (ohguide.sh) - 启动 Oracle 帮助指南文档
    • choiceDemo.cmd (choiceDemo.sh) - 启动 Oracle 帮助特性的演示
    • cshDemo.cmd (cshDemo.sh) - 启动上下文相关帮助的演示
    • helpsetDemo.cmd (helpsetDemo.sh) - 启动帮助集预览器来测试你的帮助集
    • authoringWizard.cmd (authoringWizard.bat) - 启动 Helpset 创作向导

When I set JAVA_HOME on windows I can set it with or without quotes. Either way fails :

当我在 Windows 上设置 JAVA_HOME 时,我可以使用或不使用引号来设置它。无论哪种方式都失败了:

with quotes:

带引号:

C:\Users\Amir\Desktop\ohj-5_0_0_433\ohj-5_0_0_433\bin>set JAVA_HOME="C:\Program
Files (x86)\Java\jdk1.6.0_14"
C:\Users\Amir\Desktop\ohj-5_0_0_433\ohj-5_0_0_433\bin>ohguide.cmd
C:\Users\Amir\Desktop\ohj-5_0_0_433\ohj-5_0_0_433>""C:\Program Files (x86)\Java\
jdk1.6.0_14"\bin\java.exe" -classpath "ohj.jar;help-share.jar;oracle_ice.jar;jew
t.jar;share.jar;help-demo.jar" oracle.help.demo.ChoiceDemo "demodoc\ohguide\ohgu
ide.hs"
'""C:\Program' is not recognized as an internal or external command,
operable program or batch file.

without quotes:

没有引号:

C:\Users\Amir\Desktop\ohj-5_0_0_433\ohj-5_0_0_433\bin>set JAVA_HOME=C:\Prog iles (x86)\Java\jdk1.6.0_14

C:\Users\Amir\Desktop\ohj-5_0_0_433\ohj-5_0_0_433\bin>set JAVA_HOME=C:\Prog iles (x86)\Java\jdk1.6.0_14

C:\Users\Amir\Desktop\ohj-5_0_0_433\ohj-5_0_0_433\bin>ohguide.cmd 'Files' is not recognized as an internal or external command, operable program or batch file. No Java Virtual Machine found; please set JAVA_HOME environment variable.

C:\Users\Amir\Desktop\ohj-5_0_0_433\ohj-5_0_0_433\bin>ohguide.cmd 'Files' 不是内部或外部命令,也不是可运行的程序或批处理文件。未找到 Java 虚拟机;请设置 JAVA_HOME 环境变量。

采纳答案by Eric J.

I set it in Windows System Properties and that works fine.

我在 Windows 系统属性中设置了它,效果很好。

On Vista:

在 Vista 上:

  1. Click the Start button (windows logo, lower left corner)
  2. Right-Click Computer
  3. Select Properties
  4. Select Advanced system settings (options on the left)
  5. Select Environment Variables (button)
  6. Add (or edit) a System Variable JAVA_HOME
  7. Enter your JAVA_HOME without any quotes
  8. Add to the PATH System Variable to include the path to your JDK (so you dont have to worry about how to quote it.
  9. You may also want to extend your CLASSPATH System Variable to include the ones you would specify on the command line (optional)
  1. 单击“开始”按钮(Windows 徽标,左下角)
  2. 右键单击计算机
  3. 选择属性
  4. 选择高级系统设置(左侧选项)
  5. 选择环境变量(按钮)
  6. 添加(或编辑)系统变量 JAVA_HOME
  7. 输入您的 JAVA_HOME 不带任何引号
  8. 添加到 PATH 系统变量以包含 JDK 的路径(因此您不必担心如何引用它。
  9. 您可能还想扩展您的 CLASSPATH 系统变量以包括您将在命令行中指定的那些(可选)

回答by JZeeb

The problem is caused by the blanks embedded in your JAVA_HOME. When I install the JDK on Windows, I override the installation location with a directory path that does not contain any blanks. There are still a surprising number of tools that cannot deal with blank spaces.

该问题是由嵌入在 JAVA_HOME 中的空白引起的。在 Windows 上安装 JDK 时,我使用不包含任何空格的目录路径覆盖安装位置。仍然有数量惊人的工具无法处理空格。

In your particular case, the problem caused by an inconsistency between _init.cmd and ohguide.cmd. In one place, they have double quotes around a use of OHJ_JAVA_HOME and in the other case, they do not have double quotes.

在您的特定情况下,由 _init.cmd 和 ohguide.cmd 之间的不一致引起的问题。在一个地方,它们在 OHJ_JAVA_HOME 的使用周围有双引号,而在另一种情况下,它们没有双引号。

But there is a solution - use the shortened name for the directory. You can find the name using the DIR /X command in a DOS window. For example, on my system "C:\Program Files" has the short name "C:\Proga~1". You can use this value when setting JAVA_HOME, without any quotes. e.g.

但是有一个解决方案 - 使用目录的缩写名称。您可以在 DOS 窗口中使用 DIR /X 命令查找名称。例如,在我的系统上,“C:\Program Files”的简称为“C:\Proga~1”。您可以在设置 JAVA_HOME 时使用此值,无需任何引号。例如

set JAVA_HOME=c:\progra~1\java\jdk1.6.0_14

回答by Mr. Will

In both scenarios you are using one too many quotes when you try to call the java exectuable.

在这两种情况下,当您尝试调用 java 可执行文件时,您都使用了过多的引号。

In your code this:

在您的代码中:

C:\Users\Amir\Desktop\ohj-5_0_0_433\ohj-5_0_0_433>""C:\Program Files (x86)\Java\
jdk1.6.0_14"\bin\java.exe" -classpath "ohj.jar;help-share.jar;oracle_ice.jar;jew
t.jar;share.jar;help-demo.jar" oracle.help.demo.ChoiceDemo "demodoc\ohguide\ohgu
ide.hs"

should be:

应该:

C:\Users\Amir\Desktop\ohj-5_0_0_433\ohj-5_0_0_433>"C:\Program Files (x86)\Java\
jdk1.6.0_14\bin\java.exe" -classpath "ohj.jar;help-share.jar;oracle_ice.jar;jew
t.jar;share.jar;help-demo.jar" oracle.help.demo.ChoiceDemo "demodoc\ohguide\ohgu
ide.hs"