如何将 `java` 添加到 Vista 上的命令路径?

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

How do I add `java` to the command path on Vista?

javacommand-linewindows-vistapathenvironment-variables

提问by OscarRyz

I have JDK installed in Vista. I want to run javafrom the command line. How do I configure the path variable?

我在 Vista 中安装了 JDK。我想从命令行运行java。如何配置路径变量?

If I'm not able to set the JAVA_HOMEvariable, what is an alternative?

如果我无法设置JAVA_HOME变量,有什么替代方法?

回答by OscarRyz

Open My Conputer -> General Settings -> Environment variables and add as global

打开我的电脑 -> 常规设置 -> 环境变量并添加为全局变量

Key:JAVA_HOME Value:C:\jsdk etc. etc.

键:JAVA_HOME 值:C:\jsdk 等

And then modify the Path variable

然后修改Path变量

Value ( type at the end )

值(在最后输入)

 ....something;something;something;%JAVA_HOME%\bin

Reopen your command prompt and type

重新打开命令提示符并键入

 javac 

And see if it works

看看它是否有效

EDIT

编辑

Moved my comment to the answer

将我的评论移至答案

The command prompt has some problems dealing with the empty space.

命令提示符在处理空白区域时存在一些问题。

What I usually do is install the jdk directly on C: to get rid of space in "Program Files"

我通常做的是直接在 C: 上安装 jdk 以摆脱“程序文件”中的空间

So installing it directly in C: will give you an "spaceless" path to the executable:

所以直接在 C: 中安装它会给你一个“无空间”的可执行文件路径:

  C:\jdk1.6.0_14\bin\javac

Instead of

代替

 C:\Program Files\Java\jdk1.6.0_14\bin\javac

Some times you'll get: C:\Program "executable not found" or something like that.

有时你会得到:C:\Program "executable not found" 或类似的东西。

Installing directly on C: does the trick

直接在 C 上安装:有诀窍

回答by Thorbj?rn Ravn Andersen

回答by Jus12

There is some problem with Vista and the path variable containing %JAVA_PATH%if the JAVA_PATHvalue has spaces.

有一些问题与Vista和包含路径变量%JAVA_PATH%,如果该JAVA_PATH值有空格。

I fixed this manually by setting the %JAVA_PATH%to c:\program files\Java\<whatever>and then added to c:\program files\Java\<whatever>\binto the Pathvariable in Vista.

我通过设置%JAVA_PATH%to手动修复了这个问题c:\program files\Java\<whatever>,然后添加到Vista 中c:\program files\Java\<whatever>\binPath变量。

回答by Tom Cerul

If you deleted your My Computer icon, you can also go to Control Panel -> System -> Advanced system settings (which gives you System Properties dialog) -> Advanced tab -> Environment Variables. Path is listed in the second text window.

如果您删除了“我的电脑”图标,您还可以转到控制面板 -> 系统 -> 高级系统设置(提供系统属性对话框)-> 高级选项卡 -> 环境变量。路径列在第二个文本窗口中。

回答by Mike

If the java program is available in your path then you should just be able to do;

如果 java 程序在您的路径中可用,那么您应该能够做到;

c:> java -classpath somedir com.example.Main

if java isn't available to you then you can do

如果 Java 对您不可用,那么您可以这样做

c:> SET JAVA_HOME=c:\path\to\java
c:> <same java stuff from above>

回答by erickson

Use the -classpathoption for the javacommandto specify where your classes are.

使用该命令-classpath选项java来指定您的类所在的位置。

The value of the classpath option is a list of directories, JAR archives, and ZIP archives that contain classes, structured into directories that mirror the classes' package structure. The list uses the path delimiter, which is plaform specific: on Windows, it is ";", other platforms use ":".

classpath 选项的值是包含类的目录、JAR 存档和 ZIP 存档的列表,这些类的结构化为反映类包结构的目录。该列表使用特定于平台的路径分隔符:在 Windows 上,它是“ ;”,其他平台使用“ :”。

Using the CLASSPATHenvironment variable is discouraged because changes for one program are likely to interfere with the operation of other programs.

CLASSPATH不鼓励使用环境变量,因为对一个程序的更改可能会干扰其他程序的运行。