Java 为 Eclipse IDE 启动设置环境变量

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

Setting Environment variables for Eclipse IDE launching

javaeclipseenvironment-variables

提问by Raghavendra M

I want to start a project in eclipse, but when I try to start eclipse, it doesn't open. My instructor said I'd have to set the environment variables. What is the importance of environment variables like PATH, CLASSPATH, JAVAHOMEand what are their correct values?

我想在eclipse中启动一个项目,但是当我尝试启动eclipse时,它没有打开。我的导师说我必须设置环境变量。什么是环境变量,如重要性PATHCLASSPATHJAVAHOME和他们有什么正确的价值观?

采纳答案by xyz

So that Eclipse will know where Java is.

这样 Eclipse 就会知道 Java 在哪里。

JAVA_HOMEis not used by Java itself. Some third-party programs (for example Apache Tomcat) expect one of these environment variables to be set to the installation directory of the JDK or JRE. If you are not using software that requires them, you do not need to set JAVA_HOME and JRE_HOME.

CLASSPATHis an environment variable which contains a list of directories and / or JAR files, which Java will look through when it searches for Java classes to load. You do not normally need to set the CLASSPATH environment variable. Instead of using this environment variable, you can use the -cp or -classpath option on the command line when using the javac and java commands.

PATHis an environment variable used by the operating system (Windows, Mac OS X, Linux) where it will look for native executable programs to run. You should add the bin subdirectory of your JDK installation directory to the PATH, so that you can use the javac and java commands and other JDK tools in a command prompt window. The JDK installation instructions explain how to set PATH.

Java 本身不使用JAVA_HOME。某些第三方程序(例如 Apache Tomcat)希望将这些环境变量之一设置为 JDK 或 JRE 的安装目录。如果您不使用需要它们的软件,则不需要设置 JAVA_HOME 和 JRE_HOME。

CLASSPATH是一个环境变量,它包含目录和/或 JAR 文件的列表,Java 在搜索要加载的 Java 类时会查看这些文件。您通常不需要设置 CLASSPATH 环境变量。使用 javac 和 java 命令时,您可以在命令行上使用 -cp 或 -classpath 选项,而不是使用此环境变量。

PATH是操作系统(Windows、Mac OS X、Linux)使用的环境变量,它将在其中查找要运行的本机可执行程序。您应该将JDK安装目录的bin子目录添加到PATH中,以便您可以在命令提示符窗口中使用javac和java命令以及其他JDK工具。JDK 安装说明解释了如何设置 PATH。

Source

来源

回答by Cesar

Eclipse IDE itself uses Java to start and run. On windows you should have something called environment variables like PATH and JAVA_HOME, where locations of programs can be stored. In case of Java it can be very convenient, because when you have different versions, all you have to do is to edit your PATH or your JAVA_HOME. If you don't set those variables then, programs like Eclipse might not know what to use.

Eclipse IDE 本身使用 Java 来启动和运行。在 Windows 上,你应该有一些叫做环境变量的东西,比如 PATH 和 JAVA_HOME,可以存储程序的位置。在 Java 的情况下,它可能非常方便,因为当您有不同的版本时,您所要做的就是编辑您的 PATH 或您的 JAVA_HOME。如果您不设置这些变量,那么像 Eclipse 这样的程序可能不知道该使用什么。

Classpath is slightly different because that's what your java program uses, you'll learn more about it when you will get some experience in java programming.

Classpath 略有不同,因为这是您的 java 程序使用的,当您获得一些 java 编程经验时,您将了解更多有关它的信息。

回答by Fredrik

As I understand your question, you are having problems with starting Eclipse? If so, you have most likely not a correct path to the JRE/JDK. See this FAQ for help.

据我了解您的问题,您在启动 Eclipse 时遇到问题?如果是这样,您很可能没有正确的 JRE/JDK 路径。请参阅此常见问题解答寻求帮助

In short, you typically want to set your PATH variable to point to the java executable. Note that Eclipse does not use JAVA_HOMEat all.

简而言之,您通常希望将 PATH 变量设置为指向 java 可执行文件。请注意,Eclipse 根本不使用JAVA_HOME