为什么我们在 Java PATH 变量中添加分号而不是在 JAVA_HOME 变量中添加分号?
我有一个非常基本的问题要问,为什么我们需要在 PATH 变量末尾添加分号,为什么不在 JAVA_HOME 变量中添加分号?
我读了很多书籍和论坛:
要在 PATH 变量中分隔不同的路径?或者告诉系统或 JRE 之后不要再查看。
JAVA_HOME变量是为了帮助JRE在以后的开发中寻找更多的文件和扩展,比如JDBC驱动等。
I have a very basic question to ask, that why do we need to add a semicolon at the end of PATH variable and why don't we add semicolon in JAVA_HOME variable?
I read lot of books and forums:
To separate different paths in PATH variable? or to tell the system or JRE not to look any further after that.
JAVA_HOME variable is to help the JRE to look for more files and extensions like JDBC drivers etc. in future development.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
JAVA_HOME 用于指定单个目录。 PATH 指定几个 目录,因此您可以使用分号来分隔这些目录。
JAVA_HOME is used to specify a single directory. PATH specifies several directories, so you use a semi-colon to separate those directories.
JAVA_HOME 是 JDK 或 JRE 安装的位置。很多Java相关的库和文件都存放在这里。它是单个位置,而不是一组位置,因此无需使用“;”到不同的地点。
PATH 和 CLASSPATH 变量指定多个位置,因此使用“;”来界定条目。
注意 ';'是特定于 Windows 的。
JAVA_HOME is the location of the JDK or JRE installation. Many Java related libraries and files are stored here. It is a single location, not a set of locations and therefore there is no need to use a ';' to separate locations.
The PATH and CLASSPATH variables specify multiple locations, and therefore use ';' to delimit the entries.
Note that ';' is specific to Windows.
PATH 是一个特定于操作系统的想法。它只是意味着“当我键入命令时,也检查这些路径”。默认情况下,您当前所在的目录通常位于搜索路径中。如果你想一想,你可以很容易地想象,如果你没有 PATH 的概念,那么使用命令行会有多痛苦。
因此,给定一个 PATH(具有多个目录),您需要一种方法来分隔条目。每个操作系统都可以使用任何字符,但最流行的两种是分号(在 Windows 上)和冒号(在大多数 Unix 系统上,例如 Mac OS X)。
JAVA_HOME 只是指向您首选的 Java 安装位置。一个值,因此不需要字符来分隔条目。
顺便说一句,您还将遇到 CLASSPATH,它是 Java 应用程序正在加载的所有库 (JAR) 和资源(例如属性文件)的路径。 CLASSPATH 使用与 PATH 相同的格式/字符。
作为练习,尝试编写一些循环并打印出 System.getProperties() 和 System.getenv() 的值的代码。这是查看所有小配置元素的好方法。
PATH is an operating system-specific idea. It just means, "when I type a command, check these paths as well". The current directory you are in is usually on the searched paths by default. If you think about it for a minute, you can easily imagine how much of a pain it would be to use a command line if you didn't have the idea of PATH.
So, given a PATH (with multiple directories), you need a way to separate the entries. Each operating system can use whatever character, but the two most popular are semi-colon (on Windows) and colon (on most systems Unix, e.g. Mac OS X).
JAVA_HOME just points to wherever your preferred Java installation is located. One value, so no need for a character to separate entries.
As an aside, you'll also run into CLASSPATH, which is the paths of all of the libraries (JARs) and resources (e.g. property files) your Java app is loading. CLASSPATH uses the same format/characters as PATH.
As an exercise, try writing a little bit of code that loops over and prints out the values of System.getProperties() and System.getenv(). It's a great way to see all of the little configuration elements.
分号是分隔符;它分隔路径中的多个项目。
JAVA_HOME 只指向一个位置(JDK/JRE 目录)。
您的 PATH(或 CLASSPATH)可以包含多个位置。
话虽如此,在路径末尾添加分号不会执行任何操作,并且会被忽略。
(请注意,这是 *nix 中的冒号而不是分号)
A semicolon is the delimiter; it separates multiple items in a path.
JAVA_HOME only points to one place (the JDK/JRE directory)
Your PATH (or CLASSPATH) can encompass many locations.
That being said, putting a semicolon at the end of a path doesn't do anything and is ignored.
(Note that this is a colon in *nix rather than a semicolon)
JAVA_HOME是JDK/JRE的根目录。在我的系统上,JDK_HOME 是:
C:\program files\java\jdk1.6.0_24
由于命令行工具(java、javac、jar 等)位于 bin 目录中,因此您将 %JAVA_HOME%\bin 放在 PATH 上,而不是 %JAVA_HOME% 本身...
JAVA_HOME is the root directory of JDK/JRE. On my system, JDK_HOME is:
C:\program files\java\jdk1.6.0_24
Since the command line tools (java, javac, jar, etc) are located in the bin directory, you puth %JAVA_HOME%\bin on the PATH, and not %JAVA_HOME% itself...