Java:在Windows上安装JDK后应该设置哪些必要的环境变量?

时间:2021-08-17 11:58:19

This may be self evident to power Java programmers, but may not be so for those who are just starting the Java journey.

这对于Java程序员来说可能是不言而喻的,但对于那些刚刚开始Java之旅的人来说可能并非如此。

After downloading JDK from Sun and installing it on Windows, what environment variables should one set to use javac etc.. from command line tools like vi? (see Programming Java with Vim) Also, how does one set environment variables on Windows?

从Sun下载JDK并在Windows上安装后,应该从vi等命令行工具中设置哪些环境变量来使用javac等。 (请参阅使用Vim编程Java)另外,如何在Windows上设置环境变量?

2 个解决方案

#1


6  

See How to set the path in Windows 2000 / Windows XP for changing environment variables on Windows.

有关在Windows上更改环境变量的信息,请参见如何在Windows 2000 / Windows XP中设置路径。

  1. From the desktop, right-click My Computer and click properties.
  2. 在桌面上,右键单击“我的电脑”,然后单击“属性”。

  3. In the System Properties window, click on the Advanced tab.
  4. 在“系统属性”窗口中,单击“高级”选项卡。

  5. In the Advanced section, click the Environment Variables button.
  6. 在“高级”部分中,单击“环境变量”按钮。

  7. Finally, in the Environment Variables window, highlight the path variable in the Systems Variable section and click edit. Add or modify the path lines with the paths you wish the computer to access. Each different directory is separated with a semicolon as shown below.
  8. 最后,在Environment Variables窗口中,突出显示Systems Variable部分中的路径变量,然后单击edit。使用您希望计算机访问的路径添加或修改路径行。每个不同的目录用分号分隔,如下所示。

I suggest adding a systems variable called JAVA_HOME and set that to

我建议添加一个名为JAVA_HOME的系统变量并将其设置为

C:\Program Files\Java\jdk1.6.0_13

or wherever the installer installed Java.

或安装程序安装Java的任何地方。

Then add

;%JAVA_HOME%\bin

at the end of PATH variable. Note the semicolon is not a typo.

在PATH变量的末尾。注意分号不是拼写错误。

Another important environment variable that may come in handy later is CLASSPATH. For now, this does not need to be set, but nice to keep it in mind.

另一个可能在以后派上用场的重要环境变量是CLASSPATH。现在,这不需要设置,但很好地记住它。

The class path tells SDK tools and applications where to find third-party and user-defined classes

类路径告诉SDK工具和应用程序在哪里可以找到第三方和用户定义的类

#2


2  

All you really need is to add the bin directory of the JDK to your PATH. To do this in windows, right-click on My Computer, click Properties, Advanced Settings, and Environment Variables. There, you can add the directory to your PATH variable (semicolon separated!).

您真正需要的是将JDK的bin目录添加到PATH中。要在Windows中执行此操作,请右键单击“我的电脑”,单击“属性”,“高级设置”和“环境变量”。在那里,您可以将目录添加到PATH变量(以分号分隔!)。

Now, you can open a command prompt and just type javac, etc. Also, it doesn't sound like you are the IDE type, but if you are, I highly suggest Eclipse for getting started with Java.

现在,您可以打开一个命令提示符,只需键入javac等。此外,它听起来不像您是IDE类型,但如果您是,我强烈建议Eclipse开始使用Java。

#1


6  

See How to set the path in Windows 2000 / Windows XP for changing environment variables on Windows.

有关在Windows上更改环境变量的信息,请参见如何在Windows 2000 / Windows XP中设置路径。

  1. From the desktop, right-click My Computer and click properties.
  2. 在桌面上,右键单击“我的电脑”,然后单击“属性”。

  3. In the System Properties window, click on the Advanced tab.
  4. 在“系统属性”窗口中,单击“高级”选项卡。

  5. In the Advanced section, click the Environment Variables button.
  6. 在“高级”部分中,单击“环境变量”按钮。

  7. Finally, in the Environment Variables window, highlight the path variable in the Systems Variable section and click edit. Add or modify the path lines with the paths you wish the computer to access. Each different directory is separated with a semicolon as shown below.
  8. 最后,在Environment Variables窗口中,突出显示Systems Variable部分中的路径变量,然后单击edit。使用您希望计算机访问的路径添加或修改路径行。每个不同的目录用分号分隔,如下所示。

I suggest adding a systems variable called JAVA_HOME and set that to

我建议添加一个名为JAVA_HOME的系统变量并将其设置为

C:\Program Files\Java\jdk1.6.0_13

or wherever the installer installed Java.

或安装程序安装Java的任何地方。

Then add

;%JAVA_HOME%\bin

at the end of PATH variable. Note the semicolon is not a typo.

在PATH变量的末尾。注意分号不是拼写错误。

Another important environment variable that may come in handy later is CLASSPATH. For now, this does not need to be set, but nice to keep it in mind.

另一个可能在以后派上用场的重要环境变量是CLASSPATH。现在,这不需要设置,但很好地记住它。

The class path tells SDK tools and applications where to find third-party and user-defined classes

类路径告诉SDK工具和应用程序在哪里可以找到第三方和用户定义的类

#2


2  

All you really need is to add the bin directory of the JDK to your PATH. To do this in windows, right-click on My Computer, click Properties, Advanced Settings, and Environment Variables. There, you can add the directory to your PATH variable (semicolon separated!).

您真正需要的是将JDK的bin目录添加到PATH中。要在Windows中执行此操作,请右键单击“我的电脑”,单击“属性”,“高级设置”和“环境变量”。在那里,您可以将目录添加到PATH变量(以分号分隔!)。

Now, you can open a command prompt and just type javac, etc. Also, it doesn't sound like you are the IDE type, but if you are, I highly suggest Eclipse for getting started with Java.

现在,您可以打开一个命令提示符,只需键入javac等。此外,它听起来不像您是IDE类型,但如果您是,我强烈建议Eclipse开始使用Java。