找到你要的答案

Q:Where is Java CLASSPATH in OSX?

Q:哪里是java类路径在OSX?

I have this file in my Home Directory on OSX:

public class TestClass {
    public static void main(String[] args){
        System.out.println("Hello World");
    }
}

and in Bash I am running:

Korays-MacBook-Pro:~ koraytugay$ javac TestClass.java
Korays-MacBook-Pro:~ koraytugay$ java TestClass
Hello World

But I am wondering how the virtual machine instance running loads System from the CLASSPATH as my CLASSPATH environmental variable has no values:

Korays-MacBook-Pro:~ koraytugay$ echo $CLASSPATH

Well it returns an empty row. Nothing. When echo $PATH I will see:

Korays-MacBook-Pro:~ koraytugay$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

And java itself is in:

Korays-MacBook-Pro:~ koraytugay$ whereis java
/usr/bin/java

So in Windows java will look for the directories of CLASSPATH as far as I know. How does it work in OSX? How can Java load classes without the CLASSPATH variable?

我有这个文件在OSX上我的家目录:

public class TestClass {
    public static void main(String[] args){
        System.out.println("Hello World");
    }
}

在抨击我奔跑:

Korays-MacBook-Pro:~ koraytugay$ javac TestClass.java
Korays-MacBook-Pro:~ koraytugay$ java TestClass
Hello World

但我想知道如何在虚拟机实例运行负载的系统从类路径作为我的classpath环境变量没有值:

Korays-MacBook-Pro:~ koraytugay$ echo $CLASSPATH

它返回一个空行。没有什么.当回声$路径我会看到:

Korays-MacBook-Pro:~ koraytugay$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

和java本身是:

Korays-MacBook-Pro:~ koraytugay$ whereis java
/usr/bin/java

所以在Windows java将寻找路径的目录,据我所知。它如何工作在OSX?java如何加载类没有CLASSPATH变量?

answer1: 回答1:

In addition to the classpath, the bootstrap classloader loads the core libraries from /jre/lib and /jre/lib/ext (link).

You can check the classpath at runtime like this:

System.out.println(System.getProperty("java.class.path"));

另外的路径,引导类加载器加载核心图书馆/嘉园/ lib / jre/lib/ext(链接)。

你可以在运行时这样检查路径:

System.out.println(System.getProperty("java.class.path"));
java  osx  classpath