且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是Java类路径和路径?

更新时间:2023-01-14 22:41:16

路径只是文件夹位置。 路径是您的操作系统默认查找程序的位置。如果 java javac javap 等,等等,在您的路径中,则只需输入它们的名称即可,而无需整个文件夹位置。



您的 classpath 与此相似。它是一组文件夹,包含描述类(因此称为名称)和.jar文件的.class文件,这些文件基本上是包含 .class文件的文件。您正在运行的所有代码都是在类路径之外(生成的)或在Java库之外(在技术上也是类路径的一部分)。



每次运行您可以通过传递给 java 可执行文件的参数来指定Java程序的类路径。它还从扩展文件夹中获取类,保留Java用作系统类路径的特殊文件夹,最后保留引导程序类,这是几乎所有Java程序都需要运行的一组重要类。 p>

I have been googling around, trying to understand what the Java Classpath and Path are. However, I am stil not quite sure if I have understood it or not. If feel that this topic is one of those grey areas.

Can someone explain me what those are? I mean, where do I find and set them (where is the actual text file on Mac/Windows)? Is there only one instance of each one? If so, how do I set the path for multiple classes?

As you might have notices, I am totally confused right now after reading so many different tutorials... So now I really would like to have a straight forward explanation.

Please help me, I just trying to learn :) Thank you all

A path is just a folder location. The path is where your OS will look for programs by default. If java, javac, javap, etc, etc, are in your path then you can just type their names without the entire folder location.

Your classpath is similar. It is a set of folders that contain .class files describing classes(hence the name) and .jar files, which are basically files that contain .class files. All code that you're running is either out of the classpath, generated, or out of the java libaries(also part of the classpath, techncically).

With each run of a java program you can specify a classpath by parameters passed to the java executable. It also grabs classes out of "extension folders,", special folders Java keeps around to act as a system classpath, and finally, the "bootstrap classes", which are a set of important classes almost any Java program needs to run.